Forums

How to Display A Specific Post in a Page Template? (4 posts)

  1. robinrowell88
    Member
    Posted 1 week ago #

    Thanks in advance to your responses.

    In WP 2.5 I'm trying to build something for a client where I want him to be able to edit most parts of the content via the manage > edit > pages and posts. Most pages will have a primary content column, then another column with tertiary information. I want him to be able to edit both parts of the content. I am also using custom permalinks with it set so that the page title becomes the URL %posttitle%(blahblah.com/my-page-title)

    So I have created a file called detail_page_a.php and at the top is:

    <?php
    /*
    Template Name: detail_page_a
    */
    ?>

    and that works fine and shows up in the admin as a template choice. Now I want a specific post to show up in the left column. This is where the hang-up starts. For the life of me, poking around the WP docs I can't find the solution. I tried some plugin called get-a-post but that didnt work.

    Any clues?

  2. greenshady
    Member
    Posted 1 week ago #

    Retrieve a particular posts (where 5 is the post ID):

    query_posts('p=5');

    http://codex.wordpress.org/Template_Tags/query_posts

  3. robinrowell88
    Member
    Posted 1 week ago #

    Thanks Greenshady. When I use

    <?php // retrieve one post with an ID of 1
    query_posts('p=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <h4><?php the_title(); ?></h4>
    <?php the_content(); ?>
    <?php endwhile;?>

    it won't work. I have 3 posts, and the only one it seems to work with is if I make p=0, 1 and 2 don't. All 3 are set to uncategorized.

    ???

  4. greenshady
    Member
    Posted 1 week ago #

    You should be more specific about "won't work." That means absolutely nothing when talking about code.

    This works perfectly fine:

    <?php /*
    Template Name: Query Single Post
    */
    get_header(); ?>
    	<?php query_posts('p=40'); ?>
    	<?php while (have_posts()) : the_post(); ?>
    		<h4><?php the_title(); ?></h4>
    		<?php the_content(); ?>
    	<?php endwhile;?>
    <?php get_footer(); ?>

    I found a post. The one I picked had an ID of 40. So, I set p=40. On the page I chose to use this on, I selected the "Query Single Post" post template. Clicked save and refreshed my page.

Reply

You must log in to post.

About this Topic