Sort posts by post_type in category.php template

Assuming your query does indeed have multiple post types, you’ll want to pluck them out before continuing (I assume you’re using $wp_query as your WP_Query object): <?php $all_post_types = array_map(function($item) { return $item->post_type; }, $wp_query->posts); // Now we get a unique list of post types: $unique_post_types = array_unique($all_post_types); // Use that unique list to drive … Read more

Single_cat_title() print the title before text

Set the display argument of the function to false. <h2> <?php if (is_category()){ echo ‘Category: ‘ . single_cat_title( ”, false); } ?> </h2> Or, to use the function in its more “helpful” form you could do: single_cat_title(‘Category: ‘); If the display argument is true, WordPress automatically echoes the content on to the page usually within … Read more

Custom page for WooCommerce’s /product-category/

product-category URL uses taxonomy-product-cat.php which calls archive-product.php you will need to override it by creating the same file with the same name in themefolder/woocommerce/archive-product.php You can open any file in templates folder in the WooCommerce plugin and you will find a line in the very top comment describes how to override the file. Don’t forget … Read more

Custom Stylings for category pages

@EAMann has a great answer if you want different layouts for different categories. OTOH if you only want to change the CSS to, for example, have a different background color for each category then you’ll find that most themes will include the category slug as a CSS class on the <body> element and/or possibly other … Read more

Hide tag and category boxes from the post editor

Using remove metabox function you can do this. Simply put this inside your themes functions.php file at very end. NOTE – unwrap <?php ?> if necessary. <?php function wpse60590_remove_metaboxes() { remove_meta_box( ‘categorydiv’ , ‘post’ , ‘normal’ ); remove_meta_box( ‘tagsdiv-post_tag’ , ‘post’ , ‘normal’ ); } add_action( ‘admin_menu’ , ‘wpse60590_remove_metaboxes’ ); ?>

Default category link for a custom category is a broken link

I found that the reason flush_rewrite_rules(); wasn’t working was because switch_to_blog doesn’t re-initialize some of the properties of $wp_rewrite (not to mention other parts of WP), so flush_rewrite_rules was still generating some of the rules based on the permalink structure of the current blog (which is not the same), rather than the switched-to blog (84). … Read more