ThemeShaper Forums » Thematic

[closed]

Yearly Custom Post Types

(3 posts)
  • Started 2 years ago by hanswurst
  • Latest reply from hanswurst
  • This topic is not resolved
  1. hanswurst
    Member

    Hello,

    I'm developing a thematic childtheme. On a subpage, I'm listing posts from a custom post type. By now, all runs perfect, BUT missing ONE feature: I need the posts to be seperated by years, means all 2011 posts are headed by an <h2>2011</h2>, then come the articles, then comes <h2>2010</h2>, then come the articles, and so on...all on one page, no pagination.

    For better understanding how my current code for the query looks like:

    <?php $movies= new WP_Query( array( 'post_type' => 'movies', 'genre' => 'sci-fi', 'paged' => $paged ) ); ?>
        <?php if ($movies->have_posts()) : ?>
            <?php while ($movies->have_posts()) : $movies->the_post(); ?><?php $counter++; ?>
    				<article class="item <?php thematic_post_class() ?>">
    					<a href="<?php  the_permalink(); ?>" title="<?php the_title(); ?>"> <h3 class="caption"><?php the_title(); ?></h3>
    					<img src="<?php echo get_bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php print_custom_field('coverbild:to_image_src'); ?>&h=400&w482&zc=1&amp;q=80" /></a>
    				</article><!-- .item -->
            <?php endwhile; ?>
    		<?php thematic_navigation_below(); ?>
        <?php endif; ?>

    As far as my PHP-knowledge goes, it shouldn't be so hard to get what I need? I really am a patient guy and I'm searching for a solution for 2 weeks now. In some moments I really started to question Wordpress in general, but I know that there's a solution to it, I just didn't find it yet. Does anybody know something usefull? ANY help really is APPRECIATED!

    Posted 2 years ago #
  2. stream of consciousness response:

    first, you'll need to adjust your query to get all the posts and to sort them by date (i actually think they might already be sorted by date)

    Use 'posts_per_page'=>-1 to show all posts, there will then be no need for pagination

    then i think you'd have to do some checks in your while loop.... maybe an IF statement that prints out the year the first time and then any time there is a change in the year. year should just be the_date('Y') in the loop

    and def check out wordpress.stackexchange.com for some of these more wordpress specific issues (and less thematic-specific). there are some really great nuggets to be found.

    while no answer was "Accepted" this thread seems particularly relevant:
    http://wordpress.stackexchange.com/questions/1656/display-posts-links-from-a-category-group-by-year

    Posted 2 years ago #
  3. hanswurst
    Member

    Thank you very much for the fast response. The Link is indeed very relevant, I'm working out a solution now. I'll post my finished solution here ASAP! THANK YOU!

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.