• I’m trying to pull the excerpt of a post and stick it in the sidebar. It contains the client’s contact info, so it should be up there on every page. I’m using code I found in the codex, but it’s not populating. I’m new to php, so I have no idea what I’m missing. Here’s the code:

    <div id="the-basics">
    	<p><?php
    	$my_id = 79;
    	$post_id_79 = get_post($my_id);
    	$title = $post_id_79->post_excerpt;
    	?></p>
    </div> <!-- end the-basics div -->

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter exit6

    (@exit6)

    This was a very helpful link, thanks. It helped me to solve a much larger problem on the site I was working on, which was styling two categories differently on the index page. But now I lost all the content in the sidebar! Here are the two loops on the index page:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <!-- If the post is in the category we want to exclude,
    we simply pass to the next post. -->
    <?php if (in_category('1')||in_category('3')||in_category('7')) continue; ?>
    <!-- do stuff -->
    <?php endwhile; ?>
    
    <!-- Get the four menu items for display -->
    
    <?php query_posts('category_name=menu-item&showposts=4');
    while (have_posts()) : the_post();
    $do_not_duplicate = $post->ID; ?>
    <!-- do more stuff -->
    <?php endwhile; else: ?>
    
    <p>Sorry, no posts matched your criteria.</p>
    
    <!-- REALLY stop The Loop. -->
    <?php endif; ?>

    I pulled out all the template stuff to keep this from getting too long. Any idea why would this mess up the sidebar?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can’t get specific post to display using get_post’ is closed to new replies.