WordPress.org

Ready to get started?Download WordPress

Forums

Display posts from Category (4 posts)

  1. dbUNIT16
    Member
    Posted 5 years ago #

    I am creating a template where I want to display the latest x posts from a specified category. What is the code to do this? Please include the loop if it is indeed necessary.

    Also, if possible, what would be the code if I wanted to display the first post differently, specifically with Name, Date, Title, Tags, Author, Comments etc.

    The next x posts would just have the Date, and Title as link.

    All help is appreciated!

    Thanks,

    Jon

  2. @mercime
    Volunteer Moderator
    Posted 5 years ago #

    The loop is indeed necessary. The detailed information in Codex re Category Templates should help you out.

  3. dbUNIT16
    Member
    Posted 5 years ago #

    Thanks mercime. I did look at that. I will be customizing my category templates as well, however, I want to keep their index.php structure in tack.

    The page I want to create will NOT be a substitute for the category pages. I still want to have the category pages, but want to create a template where i can specify the latest number of x posts from x category.

    Where the first post has most information, and the following x posts show simply the date, title, and link. Can you help?

    Thanks,

    Jon

  4. dbUNIT16
    Member
    Posted 5 years ago #

    So i managed to find out that this requires multiple loops. I copied the code exactly from http://codex.wordpress.org/The_Loop but still it's not showing up. I get a blank page at http://www.azfans.com/blogs/suns

    <?php $my_query = new WP_Query('category_name=Suns&showposts=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID; ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>
      <?php endwhile; ?>
    
        <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>
      <?php endwhile; endif; ?>

    Also, how would I change the second loop to only pull from the Suns or 3 category?

    Help is greatly appreciated! Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic