Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to make the code below preview a page instead of a latest category post?

<div class="one_third_last">
  <h2>Gift Vouchers</h2>
  <div class="entry">   
<?php
//The Query
query_posts('posts_per_page=1&cat=7');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   <?php if ( has_post_thumbnail()) the_post_thumbnail('medium-thumbnail'); ?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><small><?php the_time('F jS, Y') ?></small></a>
  <p><a rel="bookmark" href="<?php the_permalink(); ?>"><?php echo strip_tags(get_the_excerpt());?></a></p> 
</div>
<?php endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
<?php endif;
//Reset Query
wp_reset_query();
?>
    </div>

Thanks,

share|improve this question

1 Answer 1

up vote 0 down vote accepted

try and change this line:

query_posts('posts_per_page=1&cat=7'); 

to:

query_posts('posts_per_page=1&page_id=17'); 

or:

query_posts('posts_per_page=1&pagename=page-slug');

(enter the actual page ID or page slug into the respective space)

http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

share|improve this answer
    
Awesome! thanks Michael that did the trick. –  Nsokyi Oct 15 '11 at 14:26
    
No need for the posts_per_page argument, i very much doubt you'll get more than one result when querying by a specific page ID... ;) –  Mark Duncan Oct 15 '11 at 16:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.