[Resolved] Displaying Post(s) on Sidebar.
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.
returned, among others, this:
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.
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.
<?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.
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.
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', '« Next Video'); ?> <?php previous_post_link('%link', 'Previous Video »'); ?> <?php endforeach; endif; ?>
Excuse my lack of PHP knowledge, I’m learning (slowly).
Thanks for the help!
- The topic ‘[Resolved] Displaying Post(s) on Sidebar.’ is closed to new replies.