• Resolved nickgarren

    (@nickgarren)


    I’m using the following code to pull one recent post and display it on my page.php file, it works fine but I want to make it pull from a specific category, how can do this?

    <?php $recentpost = new WP_Query(“showposts=1”); while($recentpost->have_posts()) : $recentpost->the_post(); ?>

    Thanks

    Nick

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator t-p

    (@t-p)

    Try:
    <?php $recentpost = new WP_Query("showposts=1&&category__in=xx");

    where xx = your chosen category id.

    Thread Starter nickgarren

    (@nickgarren)

    Try:
    <?php $recentpost = new WP_Query(“showposts=1&&category__in=xx”);

    where xx = your chosen category id.

    I couldn’t get that piece of code to work, maybe I should have posted the entire snip-it of code I’m using on my page.php file

    here is my entire snip-it:

    <div id="content-inner">
    	          <h1 class="post-title">Featured Mountain Hardware Website</h1>
                       <div> &nbsp;</div>
                        <?php $recentpost = new WP_Query("showposts=1"); while($recentpost->have_posts()) : $recentpost->the_post(); ?>
                          <h1><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h1>
                           <div> &nbsp;</div>
                            <?php the_content(); ?>
                              <?php endwhile; ?>
                               </div>
    Moderator t-p

    (@t-p)

    try this:

    <?php
    //display 5 post from category 77
       $args=array(
       'showposts'=>5,
       'category__in' => array(77),
       'caller_get_posts'=>1
       );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
    the_content(); //use the_excerpt() for a summary
    ?>
    <?php
    //this is necessary to show the tags
    global $wp_query;
    $wp_query->in_the_loop = true;
    endwhile;
    }
    ?>
    Thread Starter nickgarren

    (@nickgarren)

    Thanks t-p!

    problem solved!!

    Moderator t-p

    (@t-p)

    Glad you got it working. ??

    Please mark this thread “resolved” using the dropdown in the right panel.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Recent Post From a Specific Category’ is closed to new replies.