How to put post excerpts in a page?

Discussion in 'WordPress' started by HDaddy, Oct 7, 2011.

  1. #1
    Hey!

    Making a new theme and wondering is there a way to put a post excerpt in a page. Here´s the idea:

    I make a page called SOMETHING

    Then I make a post called POST

    When a person goes to the page SOMETHING I want him to see a excerpt of the post POST.

    and when he clicks the post title or read more he gets to the full post.

    Is this possible?

    Here´s my page.php at the moment.

    
    <?php get_header(); ?>
    <div id="contentbg">
    <div id="content">
    
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    	<h2><?php the_title(); ?></h2>
    	
    	<div class="entry">
    	<?php the_content(); ?>
    	
    	</div>
    	
    	
    	<?php endwhile; else: ?>
    
    	<h2>Woops...</h2>
    
    	<p>Sorry, no posts we're found.</p>
    
    	<?php endif; ?>
    
    	<p align="center"><?php posts_nav_link(); ?></p>
    </div>
    </div>
    <div class="clear">
    	</div>
    <?php get_footer(); ?>
    
    PHP:
    Do I need a page template or a single.php file?

    I tried googling but did not find a solution.

    I´m still learning wp so much of it still a mystery for me.

    Hope you can help me.

    Thanks in advance.
     
    HDaddy, Oct 7, 2011 IP
  2. Yuuko008

    Yuuko008 Member

    Messages:
    682
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    33
    #2
    Put this <?php query_posts('p=xx'); ?>, which 'xx' is the post ID of the POST, before <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    then change the <?php the_content(); ?> to <?php the_excerpt(); ?>

    Hope my tip help =)
     
    Yuuko008, Oct 7, 2011 IP
  3. HDaddy

    HDaddy Active Member

    Messages:
    287
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Thanks! Worked like a charm! I put the code on page template so it doesnt affect other pages. One question still if you don´t mind :)

    I changed your <?php query_posts('p=xx'); ?> to this <?php query_posts('cat=movies&showposts=5'); ?> so it would only show posts from the category MOVIES. Then i made a post and put it in the GENERAL category, but it still showed up on the page where was supposed to show only MOVIES category posts. What´s wrong?

    So grateful if you could help me with this one also. Also learning php step by step still...

    Thanks!
     
    HDaddy, Oct 8, 2011 IP
  4. Yuuko008

    Yuuko008 Member

    Messages:
    682
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    33
    #4
    It is because you are using the wrong syntax. Use this instead

    <?php query_posts('category_name=movies&showposts=5'); ?>

    If I really helped giving a reputation won't hurt =))

    Thanks
     
    Yuuko008, Oct 8, 2011 IP
    HDaddy likes this.
  5. HDaddy

    HDaddy Active Member

    Messages:
    287
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Thanks that did the trick! And of course I´ll give rep...did not remember it..been a while since I´ve been in the forums :)
     
    HDaddy, Oct 8, 2011 IP
  6. Yuuko008

    Yuuko008 Member

    Messages:
    682
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    33
    #6
    no problem. Glad I helped =)
     
    Yuuko008, Oct 8, 2011 IP