Test if post has a category
Use has_category instead. if (has_category(”,$post->ID)) … If you want to use it in The Loop, you don’t need to specify the ID. if (has_category()) …
Use has_category instead. if (has_category(”,$post->ID)) … If you want to use it in The Loop, you don’t need to specify the ID. if (has_category()) …
If you want a plugin solution, advanced custom fields can do this.
Another way that @toscho’s solution made me try, and worked for me, is this scheme: http://example.com/videos/?tag=crazy
I’m a bit unsure of you are actually asking, so apologies if I understood it wrong. You can use get_category() to get the category object and then just simply echo the $count property value $cat_count = get_category( ‘ID OR ROW OBJECT’ ); echo $cat_count->count;
The wp_list_categories() function uses get_terms() behind the scenes, where the documentation for the exclude argument says: If $include is non-empty, $exclude is ignored. Instead you could try to exclude the term_id from the include values: $include = wp_filter_object_list( get_the_category(), // Data [ ‘term_id’ => 1 ], // Filter Data ‘NOT’, // Filter Option (exclude) ‘term_id’ … Read more
Change the last line to this: $output = strtr( wp_list_categories( ‘include=”.$cat_ids.”&title_li=&style=none&echo=0’ ), array( ‘<br />’ => ‘ // ‘ ) ); echo preg_replace( ‘@\s//\s\n$@’, ”, $output );
One these three should do the job for you… 1. Function: the_category(); News su <?php the_category(‘, ‘); ?> Displays as: News su WordPress, Computers, Blogging And if only a single category is assigned to a post, it shows up like this: News su WordPress 2. Function: get_the_category_list(); <div id=”pagine”><?php echo get_the_category_list(); ?></div> Displays as: <div … Read more
First off, note that, since your custom loop is a secondary loop/query, you should use the WP_Query class instead of query_posts(). Read why. That being said, /* main post’s ID, the below line must be inside the main loop */ $exclude = get_the_ID(); /* alternatively to the above, this would work outside the main loop … Read more
Firstly, $product->get_categories() won’t work because it’s a woocommerce function, that basically is just a wrapper for get_the_term_list, which has no sorting parameter. It’s always good to take a look at the source to know what you’re dealing with. Secondly,get_the_term_list uses get_the_terms, but it also has no sorting parameter. The latter get the terms either from … Read more
By default you can’t exclude terms from get_the_term_list. However, you can tweak the original function and make it exclude terms. The original function can be found in wp-includes/category-template.php lines 1277 to 1306. Add this to your functions.php. This new function, as said will exclude any term you specify <?php function get_modified_term_list( $id = 0, $taxonomy, … Read more