custom layout for posts category
-
Hi,
I need to display a posts category a particular way. The following format.
<2013>
<postname> <postname> <postname><2012>
<postname> <postname> <postname><2011>
<postname> <postname> <postname>etc..
I have the following code that works well, but it’s pulling in all the posts, I need to filter it so it only pulls in from 1 category.
<?php // get years that have posts $years = $wpdb->get_results("SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY year DESC"); foreach($years as $year) { // get posts for each year $posts_this_year = $wpdb->get_results("SELECT post_title FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = '" . $year->year . "'"); echo '<h2>' . $year->year . '</h2><ul>'; foreach($posts_this_year as $post){ echo '<li>' . $post->post_title . '</li>'; } echo '</ul>'; } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘custom layout for posts category’ is closed to new replies.