Display list of links

To show a list of links from the admin links section in a template:

 PHP |  copy code |? 
1
<?php wp_list_bookmarks( $args ); ?> 

Where $args can include the following:

 PHP |  copy code |? 
01
<?php $args = array(
02
    'orderby'          => 'name',
03
    'order'            => 'ASC',
04
    'limit'            => -1,
05
    'category'         => ,
06
    'exclude_category' => ,
07
    'category_name'    => ,
08
    'hide_invisible'   => 1,
09
    'show_updated'     => 0,
10
    'echo'             => 1,
11
    'categorize'       => 1,
12
    'title_li'         => __('Bookmarks'),
13
    'title_before'     => '<h2>',
14
    'title_after'      => '</h2>',
15
    'category_orderby' => 'name',
16
    'category_order'   => 'ASC',
17
    'class'            => 'linkcat',
18
    'category_before'  => '<li id=%id class=%class>',
19
    'show_description' => '1', 
20
    'category_after'   => '</li>' ); ?> 
21
 
22

Posted in Code, Theming, Tips and Tricks, Wordpress 3 | Leave a comment

Include Custom Template File

To include a file in the themes folder in another theme file:

 PHP |  copy code |? 
1
<?php get_template_part('special'); ?>

will include the file special.php in the current file.

Parameters are $slug and $name

 PHP |  copy code |? 
1
<?php get_template_part($slug $name); ?>

 PHP |  copy code |? 
1
<?php get_template_part('navbar' 'special'); ?>

will load navbar-special.php

ie:

slug = navbar (required)

and name = special (optional)

Posted in Theming, Tips and Tricks, Wordpress 3 | Leave a comment

Custom Sidebars

Register Custom Sidebars in THEME/functions.php

 HTML |  copy code |? 
01
add_action( 'widgets_init', 'my_register_sidebars' );
02
 
03
function my_register_sidebars() {
04
 
05
    register_sidebar( array(
06
 'name' => __( 'Primary Widget Area'),
07
 'id' => 'primary-widget-area',
08
 'description' => __( 'The primary widget area' ),
09
 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
10
 'after_widget' => '</li>',
11
 'before_title' => '<h3 class="widget-title">',
12
 'after_title' => '</h3>',
13
 ) );
14
 
15
    register_sidebar(array(
16
        'id' => 'topwidget',
17
        'name' => __('Top Widget'),
18
        'description' => __('Widget area between nav bar and content on index page'),
19
'before_widget' => '<li id="%1$s">',
20
'after_widget' => '</li>',
21
        'before_title' => '<h3 class="widget-title">',
22
        'after_title' => '</h3>' . "\n\t"
23
    ));
24
    register_sidebar(array(
25
        'id' => 'shop',
26
        'name' => __('Shop Sidebar'),
27
        'description' => __('Sidebar for shop custom post type'),
28
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 'before_widget' => '<li id="%1$s">',
29
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'after_widget' => '</li>',
30
        'before_title' => '<h3 class="widget-title">',
31
        'after_title' => '</h3>' . "\n\t"
32
    ));
33
}

Create sidebar-mycustom.php.
You will see your sidebars now listed in ‘Appearance’ -> ‘Widgets’.

In your sidebar-templates you may now call the dynamic generated content (widgets) by the name of your sidebars eg in sidebar-mycustom.php:

 PHP |  copy code |? 
1
<?php if ( function_exists ( dynamic_sidebar('custom') ) ) : ?>
2
... regular html ...
3
<?php dynamic_sidebar ('custom'); ?>
4
... regular html ...
5
<?php endif; ?>

Integrate your sidebars in your template-files (e.g. index.php, single.php, archives.php):

Default sidebar:

 PHP |  copy code |? 
1
<?php get_sidebar (); ?>

Custom Sidebar:

 PHP |  copy code |? 
1
<?php get_sidebar ('mycustom'); ?>

Notes:

  • sidebar file name does not need to be relates to the registered sidebar name
  • registered name is used to call the dynamic sidebar eg: custom
  • custom sidebar file is called from template using get_sidebar(‘mycustom’)
Posted in Theming, Wordpress 3 | Leave a comment

NextGen Gallery Template Files

Template files can be saved in /wp-content/themes/YOUR-THEME/nggallery and called in the short tag parameters.

 HTML |  copy code |? 
1
[nggallery  id=1 template=niceone]

This will use template file gallery-niceone.php in your theme folder.

It will default to gallery.php if template file is not found.

Similarly for albums and image browsers:

 HTML |  copy code |? 
1
[album id=3 template=coolone]

 HTML |  copy code |? 
1
[imagebrowser id=6 template=bigwindow]

Posted in NextGen Gallery, Wordpress 3 | Leave a comment

Control Interval of Automatic Revisions in WordPress

In wp-config.php, before ABSPATH;

 PHP |  copy code |? 
1
define('AUTOSAVE_INTERVAL',120)

Interval is in seconds

Posted in Code, Tips and Tricks, Wordpress 3 | Leave a comment

Control Number of Revisions in WordPress

In wp-config.php

 PHP |  copy code |? 
1
define('WP_POST_REVISIONS', 10);

0 = no revisions

Posted in Code, Tips and Tricks, Wordpress 3 | Leave a comment

Remove line breaks and returns (\n\r) from string

 PHP |  copy code |? 
1
$newstring = trim( preg_replace( '/\s+/', ' ', $string ) );

Posted in PHP | Leave a comment

mySQL text find and replace in field

 SQL |  copy code |? 
1
UPDATE TABLE_NAME SET column_name = REPLACE (column_name, 'current string', 'new string');

Posted in SQL | Leave a comment

WordPress change image links etc in database

 SQL |  copy code |? 
1
UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.oldurl.com', 'http://www.newurl.com');

Posted in SQL, Tips and Tricks, Wordpress 3 | Leave a comment

WordPress 3 Delete Post Revisions

 SQL |  copy code |? 
1
DELETE a,b,c FROM wp_posts a
2
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
3
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
4
WHERE a.post_type = 'revision'

Posted in SQL, Tips and Tricks, Wordpress 3 | Leave a comment