WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category Specific Template (5 posts)

  1. archaeologyman
    Member
    Posted 5 years ago #

    I am attempting to create a page template that calls for just one category as opposed to calling all posts.

    Could someone advise on how to do this?

    Thanks.

    I am assuming that I need to add code somewhere in here?:

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=5'.'&paged='.$paged);
    if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
    global $more; $more = 0;
    ?>
    
    		<h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    		<p><?php the_time('F j, Y'); ?></p>
    
    <?php the_content(); ?>
  2. lifestyler
    Member
    Posted 5 years ago #

    in your template file where you want to show it.

  3. archaeologyman
    Member
    Posted 5 years ago #

    I specifically want to call just one category, the code I posted calls all of the posts. What do I need to alter in the code I posted to call just, let's say, category 5 for instance?

    Thanks.

  4. WebDev WaxLotus LLC
    Member
    Posted 5 years ago #

    $my_query = new WP_Query("showposts=1&category_name=News");

    or

    $my_query = new WP_Query("showposts=1&cat=5");

  5. archaeoman
    Member
    Posted 5 years ago #

    Thank you. That did it.

Topic Closed

This topic has been closed to new replies.

About this Topic