I’m trying to make a list of my recent posts that also show what category they are in right now I have
<?php $args = array( 'numberposts' => 30) ;
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li>
<a href="'.get_permalink($recent["ID"]).'" title="Look'.esc_attr($recent["post_title"]).'" > '.$recent["post_title"].'</a> </li> '; } ?>
this displays the post but I would like it to also display the category name.
Any help would be great,
Thanks
You can try this inside the loop (if you have multiple categories)
I was able to get this to work using the following.
So in the recent posts loop you can use it like this:
I was able to get a list that displays the category then the title by using the following.
I was never able to get the following code to work inside my original code It would always show up as “array” or Null (i’m guessing I just did not know the proper way to write it in) I was able to get it to show the category if I created a single post and just wanted to show the category with nothing else.
I used the answer from Jaco, but
gave me the first category from the array on each post. The adjustment I made was to use an incremental operator in my code and all is well.
A much simplified example: