Title: Adding posts to sidebar with custom code
Last modified: August 19, 2016

---

# Adding posts to sidebar with custom code

 *  [Drew Baker](https://wordpress.org/support/users/dbaker/)
 * (@dbaker)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/adding-posts-to-sidebar-with-custom-code/)
 * 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: [http://www.popmag.com.au](http://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)

 *  Thread Starter [Drew Baker](https://wordpress.org/support/users/dbaker/)
 * (@dbaker)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/adding-posts-to-sidebar-with-custom-code/#post-836635)
 * Bump. Anyone?

Viewing 1 replies (of 1 total)

The topic ‘Adding posts to sidebar with custom code’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Drew Baker](https://wordpress.org/support/users/dbaker/)
 * Last activity: [17 years, 9 months ago](https://wordpress.org/support/topic/adding-posts-to-sidebar-with-custom-code/#post-836635)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
