Latest posts list with category id as a class on list items
-
Hi guys,
I am trying to output a list of recent posts, but would like to style each list item depending on the category the post is saved in.IE, the list output would look something like this:
<ul id="myposts"> <li class="cat-books"><a href="#" title="post title">post title</a> <li class="cat-movies"><a href="#" title="post title">post title</a> <li class="cat-books"><a href="#" title="post title">post title</a> <li class="cat-music"><a href="#" title="post title">post title</a> <li class="cat-movies"><a href="#" title="post title">post title</a> </ul>
This is the code that i am trying:
<?php query_posts('showposts=10'); ?> <ul id="myposts"> <?php while (have_posts()) : the_post(); ?> <li class="cat-<?php $posts->cat_name; ?>"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul>
I realize it was a long shot and it makes sense why its not working, since i havent added any code to retrieve anything from the terms table in the db.
Anyone fancy pointing me in the right direction?
Cheers,
Chris
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Latest posts list with category id as a class on list items’ is closed to new replies.