WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Displaying Post(s) on Sidebar.

[Resolved] Displaying Post(s) on Sidebar.

  • Greetings,

    What I’m trying to do is fairly simple… in my mind anyway. What I’m trying to do is take posts from a category, which will call “sideposts” for now, and actually display the post data on my sidebar.

    However, I can’t figure out the code to add to my Sidebar.php to select the posts from category “sideposts” and display them.

    Could someone please give me the basic PHP code to select the posts from “sideposts” category and to display the latest 10 posts or so? It would be much appreciated.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Michael:

    I did some searching as well… however I can’t quite find what I’m looking to achieve.

    I’m not looking to put LINKS to posts in my sidebar. I’m looking to put the actual content of the post on my sidebar.

    This is what I’ve attempted thus far, which is the best I’ve tried. (It doesn’t give me “the_content()” – but it doesn’t error out.)

    <?php $postlist = get_posts('category=3&numberposts=2');
    foreach ($postlist as $post) :?><li><?php the_content(); ?></li><?php endforeach; ?>

    EDIT: I guess it would help if I had some posts in that category. However, with the category specified, it is now showing the post in the only other category I have.

    Search for keywords like asides, sideblog, miniblog etc.

    Actually, I’ve almost got it working. I’ve run into a conflict though.

    If I don’t filter, by category, the post list on the main index, the effect I’m going for works. However, if I try to filter the main index, the filter on the sidebar no longer works.

    I will continue to search around.

    How about:

    <?php
    $postlist = get_posts('category=3&numberposts=2');
    if ($postlist):
    foreach ($postlist as $post) :
    setup_postdata($post);
    the_content();
    endforeach;
    endif;
    ?>

    That example I linked to was missing the setup_postdata…I’ll comment on that post.

    Michael,

    That did it. Thank you very much, it was driving me crazy. I’m not extremely well versed in PHP, I know just enough to roll around it and break things… but I guess that’s how we learn.

    Thanks again.

    Hey Guys,
    This little piece of code is exactly what I’ve been looking for!

    Although, I am having some issues. I’m trying to use it to show a post’s content on the sidebar, with that posts title and links to go to the previous post from that category (preferably in the sidebar). I’m real close to getting it to work, but the posts title just shows up as the title of the page I’m currently viewing and the prevous/next links don’t show up at all.

    Here is the code I’m using:

    <?php
    $postlist = get_posts('category=438&numberposts=2');
    if ($postlist):
    foreach ($postlist as $post) :
    setup_postdata($post);?>
    <div class="posttop">
    <?php the_title(); ?><br />
    </div>
    <?php the_content(); ?>
    <?php next_post_link('%link', '&laquo; Next Video'); ?>
    <?php previous_post_link('%link', 'Previous Video &raquo;'); ?>
    <?php endforeach;
    endif;
    ?>

    Excuse my lack of PHP knowledge, I’m learning (slowly).

    Thanks for the help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Displaying Post(s) on Sidebar.’ is closed to new replies.