Articles of get the category

Add Class While on Current Post; wp_list_categories

The code below produces a sub-menu of child categories of the currently active parent category. This code also produces the child categories of the top parent category while viewing child categories and posts in those categories. The .current-cat CSS class is applied to the active child categories. This is the most nimble code I have […]

How to add a rel attribute to images that contains their categories?

I’ve added categories to images, so that I can use them to filter images within a portfolio page. Now I’m thinking I need to add the rel attribute to each image that contains its assigned categories. Is this the right approach? If so, how do I add add rel with the applicable categories?

Get posts with at least one category in common with current post?

In single.php : I want to get all posts with at least one category in common with the current post. I tried reading through the wordpress codex documentation but I found it rather confusing (I’m new to php & wordpress!). I’ve already used php on wordpress but when it comes to getting posts using filters […]

Add body class of category parent

I am not a coder, but I usually get by with WordPress by doing my research and find my solution. I can’t find what I need to do this time so I have attempted to crib together some code – what I am attempting to do is, when I am on the Category Archive, I […]

Add classname to the_category() function?

is it possible to use add_filter or something similar to add the slug of the category as classname to the the_category() function? Right now when using the_category() the output looks like this … <ul class=”post-categories”> <li> <a href=”http://mysite.com/something” title=”” rel=”category tag”>News</a> </li> </ul> Is it possible to somehow get this … <ul class=”post-categories”> <li class=”category-news”> […]

How can I get archives for specific category without category_base in the url?

I’m using this code to get archives for a specific category: function extend_date_archives_add_rewrite_rules($wp_rewrite){ $rules = array(); $structures = array( $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_date_permastruct(), $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_month_permastruct(), $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_year_permastruct(), ); foreach( $structures as $s ){ $rules += $wp_rewrite->generate_rewrite_rules($s); } $wp_rewrite->rules = $rules + $wp_rewrite->rules; } add_action(‘generate_rewrite_rules’, ‘extend_date_archives_add_rewrite_rules’); It works fine and I get an URL like: […]

Get the category is not working on url

Although this is my first post but i have been coming here for answers so I know the rule and this isn’t a duplicate because i have tried whatever i could but couldn’t seem to get my codes to work. Note that I have gone through many answers and tried out several ways but none […]

Specified number of categoy posts not showing correctly

I have a code, i used to call a particular category in my post page footer and i have specified the number of posts to display but its showing all the posts from that category. here are the codes <?php query_posts(‘category_name=tech&order=dsc&showposts=12’); ?> and <?php query_posts(‘cat=438’.’&showposts=7′); ?> any help please, i really need the post to […]

Get the number of posts in a named category, outside the loop

I’ve managed to do this from a single.php file, inside the loop, but now I need to do it from another page. I need to find out how many live posts are in category named every story (slug is everystory). I am not inside the loop. I just need the number, I don’t need to […]

Get a variable from object in array

I’m trying to echo get_the_category($id)[0]->slug and this works on localhost but not on the server. The error is Parse error: syntax error, unexpected ‘[‘…. Is there a workaround?