A plugin to change the default category in permalink

Did you ever needed to change the category in the permalink. If you have say a post in two category and you have a permalink structure /%category%/%postname%/ Then the wordpress by default chooses the lowest id category for your posts permalink but with this plugin you can change it to the desired category. It was really helpful for me. you can try this.
Plugin url: http://wordpress.org/extend/plugins/hikari-category-permalink/

Posted in tips and hacks | Leave a comment

Changes in wp_capabilities meta field in wordpress 3.0

There is changes in wordpress wp_capabilities meta field for users in wordpress 3.0, I noticed it when i had to list authors of the site.
For author the wp_capability meta field was

a:1:{s:6:"author";b:1;}

New one is

a:1:{s:6:"author";s:1:"1";}

So to list new authors you will have to check the users capability against the new one.

Posted in tips and hacks | Leave a comment

Single template according to category

In recent one of my project i had to use single template according to the category the post is in. It also checks parent category it is in to select desired template. I tried following and it worked perfectly. you have to make new template with single-categoryname.php

        add_filter('single_template', 'wpexpo_single_template');
	function wpexpo_single_template($t)
	{
		foreach( (array) get_the_category() as $cat ) {
			if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") ) {
				return TEMPLATEPATH . "/single-{$cat->slug}.php";
			}
			if($cat->category_parent!=0){
				$parent_cat = get_category($cat->category_parent);
				if(file_exists(TEMPLATEPATH . "/single-{$parent_cat->slug}.php")) {
					return TEMPLATEPATH . "/single-{$parent_cat->slug}.php";
				}
			}
		}
		return $t;
	}
Posted in tutorial | 1 Comment

Using parent category template in sub category pages in wordpress

Have you ever tried of using parent category template to the sub categories. Here is a way to do it. Use the following code below to your functions.php file and you can use parent category template to subcategories.

For example you have category template file category-category-slug.php and we have a sub category of category-slug then all subcategory of category-slug will use this template if they don’t find their own template.
Continue reading

Posted in tutorial | 3 Comments

How to use new wordpress 3.0 header image feature

WordPress 3.0 has made it very easy to use Header image in your wordpress theme for customization. you can now use this functionality to provide the customization in your theme. please follow following guidelines to achieve it in your theme. Continue reading

Posted in tutorial | Tagged | Leave a comment

Getting current page slug in wordpress

Today i was coding a theme and i needed to get the current page’s slug so here is the code that we can use to get the page’s slug.

$post_obj = $wp_query->get_queried_object();
$slug = $post_obj->post_name;

Posted in tutorial | Tagged | Leave a comment

Some excerpt filters

Here are some excerpt filter for wordpress that i find useful. This codes go in to your theme functions.php file
1. If you need to remove unwanted tags <p> from the the_excerpt()

remove_filter('the_excerpt', 'wpautop');

Continue reading

Posted in tutorial | Tagged | Leave a comment

customizing the wordpress menu system

WordPress default menu system is great but what if you need more customizations that you cannot simply achieve with wp_nav_menu() function. Below is the code that i used to get the array of menu items and then customize it according to my usage.

<?php
function wpexpo_menu($menu='pass menu name here'){
		$nav_menu = wp_get_nav_menu_items($menu);
		$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		?>
        <ul>
		<?php
		$count = count($nav_menu);
$i = 1;
		foreach($nav_menu as $menu):
		$item_url = strpos( $menu->url, '#' ) ? substr( $menu->url, 0, strpos( $menu->url, '#' ) ) : $menu->url;
		$li_class = ($current_url==$item_url?' class="current-menu-item"':'');
		?>
            <li<?php echo $li_class?>><a href="<?php echo $menu->url?>"><?php echo $menu->title;?></a></li>
			<?php if($i<$count):?><li>|</li><?php endif;?>
        <?php
		$i++;
		endforeach;
		?>
        </ul>
        <?php
	}
?>

Continue reading

Posted in tutorial | Tagged | Leave a comment

Using 3.0 nav menu system in your theme

WordPress 3.0 comes up with the shiny menu system out of the box now. To use it follow following instructions.
1. open your theme functions.php file and add following code in it.

function wpexpo_init() {
		register_nav_menus(
			array(
				'primary' => __( 'Primary Menu' )
			)
		);
	}
	add_action('init', 'wpexpo_init');

Continue reading

Posted in tutorial | Tagged , | Leave a comment

Adding different sizes for the post thumbnail in wordpress

You might have used post thumbnail featured that came with wordpress 2.9.2. Well I use it a lot in many of my projects. So you might want to get the thumbnail size resized to say some fixed width and height. You can use following code for it.

you can enable post thumbnail with following code in your theme functions.php file.

add_theme_support('post-thumbnails');

Continue reading

Posted in tutorial | Tagged | 2 Comments