Code to pull in a PHP file named after the category ID

<?php foreach((get_the_category()) as $category) { if( file_exists( ‘/path/to/file/to/include/’ . $category->cat_ID . ‘.php’ ) ) include( ‘/path/to/file/to/include/’ . $category->cat_ID . ‘.php’ ); } ?> That should do the trick. If the file doesn’t exist, it just skips it. This can be expensive to do if you have a large amount of categories to loop through, though. … Read more

a-z list, categories and sub categories in loop

So you want to list the categories in a tree structure, in alphabetical order, showing ALL categories (even empty ones)? If so, try this: <?php $args = array(‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘hide_empty’ => false); $categories = wp_list_categories($args); ?> Reference: wp_list_categories

Multiple menu items highlighted

This question was also asked on stackoverflow. Here’s a copy of the answer i gave there: Perhaps you could style it using the nth-of-type CSS3 selector. .current-menu-item:nth-of-type(1) { background:#ffff00; /* Highlight styles */ } These styles would target only the first occurrence of the .current-menu-item. Likewise, you could choose to target the second with nth-of-type(2), … Read more

Show category children, one level

Why are you using the parameter parent=1? If you remove this parameter it should work. If you want children and grandchildren, you should use: $categories = get_categories(‘hide_empty=0&child_of=”.$cat); If you want only direct children, you should use: $categories= get_categories(“hide_empty=0&parent=”.$cat); Also note that you are echoing $mycat inside the loop, and you are joining the multiple categories … Read more

Edit the markup of categories list

List of possibilities You got exactly two options to alter the output of wp_list_categories() Use a filter after the MarkUp was generated and re-format it: add_filter( ‘wp_list_categories’, ‘wpse88292_reformat_list_cats’, 10, 2 ); function wpse88292_reformat_list_cats( $output, $args ) { // Reformat `$output` here // You can use `$args` to only this when condition X == Y return … Read more

How to find the number of Tags a post has?

for tags you can use $tags = get_tags(); $categories = get_categories(); $no_of_tags = count($tags); $no_of_categories = count($categories); refer this if you need more details : http://codex.wordpress.org/Function_Reference/get_tags http://codex.wordpress.org/Function_Reference/get_categories

Retrieve all posts within tag OR category?

You need a tax_query. $live_tags = array( ‘posts_per_page’ => 5, // showposts has been deprecated for a long time ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘slug’, ‘terms’ => ‘live’, ), array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => ‘candy’, ), ), ‘orderby’ … Read more