How to display a list of categories

I will show you how to display a list of categories in WordPress and also mark the active category, see code below: <?php // Get the current queried object $term = get_queried_object(); $term_id = ( isset( $term->term_id ) ) ? (int) $term->term_id : 0; $categories = get_categories( array( ‘taxonomy’ => ‘category’, // Taxonomy to retrieve … Read more

How to make a relationship between books and authors?

To build relationships, I know of two plugins, both very well coded and maintained: Posts 2 Posts Efficient many-to-many connections between posts, pages, custom post types, users. Advanced Custom Fields – this one would need the add-on Users Select, but as the plugin is being completely rewritten and will change the add-on management, it would … Read more

what is the action hook code to supporting product category condition in single product page of woocommerce?

Firstly, this conditional returns true on category archives for Woo Commerce and NOT single product page. Try using the actual slug in lowercase or the i.d. Example: if ( is_product_category( ‘t-shirt’ ) ) { Your code looks like its wrong because it includes too many brackets. Woo suggest using the slug in their Docs. This … Read more

How to Include the Parent and Child Category in the Permalink if the Post is Added to Both

There are a few answers, scattered around this forum. To summarise: Configure your Permalinks: Head to Dashboard > Settings > Permalinks Scroll down to ‘Product Permalinks’ and select ‘Custom Base’. Enter /%category%/ into the text field and then select ‘Save’. Assign Product Categories: If your products are still not showing the Child Categories, within the … Read more

Display only deepest category on a single post?

I come to this post as i was looking for the code. But the marked answer not working for me anymore. I have wrote a function to get the deepest level category assigned to a post. function post_deepest_level_cat($post_categories) { foreach ($post_categories as $category) { $cat_ids[] = $category->term_id; } $tree_args = array( ‘current_category’ => $cat_ids, ‘depth’ … Read more

Exclude Category From Home Page, Display Posts on It’s Own Page?

Rather than performing a separate query, to exclude a category (or any other taxonomy) term, you can hook into pre_get_posts: add_action(‘pre_get_posts’, ‘wpse41820_exclude_cat_from_front_page’); function wpse41820_exclude_cat_from_front_page( $query ){ if( $query->is_main_query() && is_front_page() ){ $tax_query = array(array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array( 57 ), ‘operator’ => ‘NOT IN’ )); $query->set(‘tax_query’,$tax_query); } return $query; } … Read more

Sort category page with custom field

I added the query_posts so we can tell WordPress of a modified query to run. $query_string will let us add onto the current parameters. orderby, meta_key, order let us define the query by telling it how to sort the results More information on ordering by parameters <?php wp_reset_query(); ?> <div id=”content”> <div id=”postFuncs”> <div id=”funcStyler”><a … Read more

Category menu item and its last 10 posts as sub-menu

I finally achieve it with this code in function.php // Front end only, don’t hack on the settings page if ( ! is_admin() ) { // Hook in early to modify the menu // This is before the CSS “selected” classes are calculated add_filter( ‘wp_get_nav_menu_items’, ‘display_lasts_ten_posts_for_categories_menu_item’, 10, 3 ); } // Add the ten last … Read more

How can I only show certain posts?

I haven’t had time to test this, but you can probably do this with the the_content filter hook. This way you won’t have to insert this code into archive.php, category.php, tag.php, author.php and any other archive file depending on how your theme is structured. In your theme’s functions.php file add the following: function my_filter( $content … Read more