• Hey Guys,
    I’ve been working on this little piece of code to put a post’s content on my sidebar, but I can’t get it to work.

    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).

    In case you’re wondering why I want to do this, it’s because I want to have a video highlight appear on my sidebar with the option to see old video as well. You can see my progress here: https://www.popmag.com.au

    Ideally this would be AJAX and wouldn’t require a page reload to see the old videos, but lets take it slow.

    Thanks for the help!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Adding posts to sidebar with custom code’ is closed to new replies.