WordPress.org

Forums

Most Recent Post Per Category (5 posts)

  1. leclaeli
    Member
    Posted 2 years ago #

    I have a portfolio website with several categories and the portfolio page shows all of the posts in order of date. However, I would like to display the most recent post from each category first and then have all the rest display after. Here is the code from the portfolio template page.

    <?php include_once (TEMPLATEPATH . '/title.php');?>
          <?php $values = get_post_custom_values("category-include"); $cat=$values[0];  ?>
          <?php global $more;	$more = 0;?>
          <?php $wp_query = new WP_Query(); ?>
          <?php $catinclude = 'portfoliocat='. $cat ;?>
          <?php $wp_query->query("post_type=portfolio" . '&' . $catinclude .' &paged='.$paged.'&posts_per_page=-1'); ?>
          <?php get_template_part( 'loop', 'portfolio' );?>
  2. dadvan
    Member
    Posted 2 years ago #

    try this:

    <?php include_once (TEMPLATEPATH . '/title.php');?>
          <?php $values = get_post_custom_values("category-include"); $cat=$values[0];  ?>
          <?php global $more;	$more = 0;?>
          <?php $wp_query = new WP_Query(); ?>
          <?php $catinclude = 'portfoliocat='. $cat ;?>
          <?php $wp_query->query("post_type=portfolio" . '&' . $catinclude .' &paged='.$paged.'&posts_per_page=-1&orderby=date&order=DESC'); ?>
          <?php get_template_part( 'loop', 'portfolio' );?>
  3. leclaeli
    Member
    Posted 2 years ago #

    Thanks for the reply, but that's exactly what is happening already. The issue is that if the last few posts are from the same category, all those posts show up first. I just want the last one from each category to appear first.

    Example here

    As you can see there are all "Trailers" at the the top of the page because those were most recently posted. I'd like the other categories (vehicles, semi-trucks, emergency, etc...) to have a spot at the top as well.

  4. dadvan
    Member
    Posted 2 years ago #

    OK, I see. So you want the the newest/most recent post from each category to show first but do you have 30+ categories? If not, whats to happen after you show the newest category or do you just want to show the newest from each category and then end it from there?

  5. leclaeli
    Member
    Posted 2 years ago #

    Yes, that's what I want and no I don't have 30+ categories. I'd like the rest of the posts to fill the rest of the page. What's the significance of 30?
    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic