Insert Into Sub-child Menu

Check that you actually have categories before creating the list, and move the lines that echo the <ul> inside the conditional. $categories = get_the_category(); if (!empty($categories)) { foreach($categories as $category){ $parent = $category->parent; if($parent != 0){ echo ‘<ul style=”background:#000″>’; wp_list_categories(“child_of={$parent}&title_li”); echo ‘</ul>’; } } } This will generate multiple lists, not just one. Here is … Read more

New Theme creation

I found Ian Stewart‘s Theme Development tutorial a wonderful one to start from the scratch with a very little knowledge on WordPress. How To Create a WordPress Theme: The Ultimate WordPress Theme Tutorial Hope the explanation there could help you a lot to understand which code block’s for what. So you can modify yours as … Read more

Show Featured products in product category pages

I just double checked and WooCommerce runs the product category description through the_content filters, which means that it should run shortcodes. WooCommerce has plenty of shortcodes, see their documentation Including featured products: [featured_products per_page=”12″ columns=”4″] The downside to that is that the featured products might not all be from that specific category. You didn’t mention … Read more

Show Different Custom Menu on Different Category Pages

Add a new menu called category-menu: if( function_exists( “wp_nav_menu’ ) ) { add_theme_support( ‘nav-menus’ ); register_nav_menus( array( ‘primary-menu’ => __( ‘Primary Menu’, ‘woothemes’ ) )); register_nav_menus( array( ‘top-menu’ => __( ‘Top Menu’, ‘woothemes’ ) )); register_nav_menus( array( ‘category-menu’ => __( ‘Category Menu’, ‘woothemes’ ) )); } And output it with the conditional is_category(): if( function_exists( … Read more

How to get category name from URL and pass to a template

Rather than creating pages and assigning a template, I would use the category_template filter to load a specific template for all those particular categories. In this example I use a hardcoded array, but this could be adapted to load an option which stores the category slugs you want the template applied to. function wpa_category_template( $templates=”” … Read more

Set the default category of an attachment

To solve the problem 1, you could hook to add_attachment and edit_attachment hook. add_action(‘add_attachment’, ‘wpse_set_attachment_category’); add_action(‘edit_attachment’, ‘wpse_set_attachment_category’); function wpse_set_attachment_category( $post_ID ) { // if attachment already have categories, stop here if( wp_get_object_terms( $post_ID, ‘category’ ) ) return; // no, then get the default one $post_category = array( get_option(‘default_category’) ); // then set category if default … Read more

Random taxonomy category list

There is no default way to sort terms randomly. There are ways to do this using php. First, you’ll need to remove the number argument from get_terms. As your code currently stands, you are getting 5 terms and shuffling them around. For this to work, you’ll need to retrieve all the terms from your taxonomy, … Read more