WordPress.org

Ready to get started?Download WordPress

Forums

How to show "Recent Posts" (15 posts)

  1. mrjoncrowe
    Member
    Posted 5 years ago #

    I am trying to show for instance Five Most Recent Posts on my sidebar. I would like just the Title of the post. How do I do that? Does WP make it easy for me to do that, is there a plugin? I would like to format it as well. Any help is much appreciated!

    Thanks!

  2. jbbrwcky
    Member
    Posted 5 years ago #

    Try this:

    <ul id="recentposts">
    <?php get_archives('postbypost', '5', 'html', '', '', FALSE); ?>
    </ul>

    Then style ul#recentposts {} to your heart's content.

  3. mrjoncrowe
    Member
    Posted 5 years ago #

    You my friend.... are the man. Thank you for that.

  4. gregbarr23
    Member
    Posted 5 years ago #

    Is it possible to have the default "Recent Posts" widget display and or not display posts by category?

    I love WP so much as the platform for my blog that I've decided to migrate my entire (non-blog) site to wordpress. Most of the content will be as 'pages' but I'm thinking of doing some things like news releases and job listings as 'posts' so I automatically get a category page that displays excerpts of each release or opening.

    So I want my "Recent Posts" widget to display posts of any category within the blog environment, but NOT display posts of category X, Y and Z because those are pages of my site. I've found plugins that create category-specific widgets, but that's not what I need.

    I've debated setting it all up as discrete instances of wordpress, one for the blog and one for the site, but would prefer to not have to do that. Or would that be a good idea?

  5. xdesi
    Member
    Posted 5 years ago #

    So you just want to retrieve a list blog titles from categories of your choice?
    This can be done via a query:
    http://codex.wordpress.org/Template_Tags/query_posts
    So you search through all your posts,
    limiting the categories it searches through,
    and limiting the amount of results to display.
    Then after the query you choose what you want to display from the query, e.g the blog title.

  6. gregbarr23
    Member
    Posted 5 years ago #

    Thanks, that was a helpful start. On that page I found a way to exclude posts of a certain category from the loop, so they don't appear on my home page. But they're stilling showing up in the default "Recent Posts" widget.

    That trick I used to exclude posts from a certain category on teh home page was this:

    <?php
    if (is_home()) {
    query_posts("cat=-20");
    }
    ?>

    So if there were a way to add that same code, or logic, to the "Recent Posts" widget, that's what I really need.

  7. xdesi
    Member
    Posted 5 years ago #

    Well you can just create your own widget without the use of a plugin :)

    Try something like:

    <?php query_posts('cat=-20'); ?>
    <li>
    	<h2>Recent Posts</h2>
    	<ul>
    		<?php while (have_posts()) : the_post(); ?>
    		<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
    		<?php endwhile; ?>
    	</ul>
    </li>

    So we are running the query at the start
    Then creating the sidebar slot and design, might not need to do this if you are using text box in widget editor.
    Then we decide what to show from the found posts, here we are giving a link to the posts found.

  8. gregbarr23
    Member
    Posted 5 years ago #

    First, thanks a ton for your help Xdesi. This PHP stuff is over my head but with the help of smart helpful folks like you I can do some amazing stuff with WordPress. Standing on the shoulders of giants, right?

    Unfortunately I tried the iteration of your suggestion that I figured I could handle -- dropping that code you provided into the "text box" widget. It didn't work, because the php isn't parsing, i.e. it's just appearing in the final/output html of my page.

    Got any tricks to get it to parse? Else I'll need to treat it as a discrete widget and can't find a me-friendly way to do that.

    I did find a plugin that goes 98% of the way to what I want to do, called Fuzzy Widget. It lets you display recent posts at any level of granularity of category, and even has an "exclude" function, but for some reason the exclude function works only by post or page ID, not category ID. Bummer.

  9. xdesi
    Member
    Posted 5 years ago #

    A plugin called PHPExec I think it is allows you to enter PHP into your textbox widgets etc..

    If this still doesn't work then you could simply add it to your sidebar.php manually as one of the items with the

  10. and so forth.

    But PHP Exec should let you do it :)

    Most of this PHP stuff is over my head aswell tbh, but I just try to help where I can, because other people help me, and hopefully gain myself experience and knowledge while helping others.

  • gregbarr23
    Member
    Posted 5 years ago #

    You RULE, xdesi!!! Thanks for stickin with me.

    It's called Exec-PHP and it worked like a friggin' CHARM!!!

    In summary, with your help I am now able to hide/mask posts of specific categories on my home page by adding this to index.php:
    <?php if (is_home()) { query_posts("cat=-20"); } ?> to index.php.

    And I can replace the default Recent Posts widget with a customizable one that lets me show or hide posts by categories.
    1) Install the Exec-PHP plug-in.
    2) Add this to the "text box" widget:

    <?php query_posts('cat=-20'); ?>
    <li>
    <h2>Recent Posts</h2>
    <ul>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    </li>

    This going to let me build my entire site, blog and non-blog, on WordPress, and create certain content of my 'site' as posts instead of pages, where I decide that's appropriate.

    Damn, I just thought of my next issue: having posts of certain categories (i.e. press releases, job postings) not be part of my RSS feed. If you have any thoughts on that I'd appreciate it, but I'll probably spin this off as yet another 'wordpress as a cms' thread since the ones I've found say "do your site and blog as one instance" but don't address these problems.

  • gregbarr23
    Member
    Posted 5 years ago #

    Damnit.

    An unfortunate correction. The widget trick doesn't work in IE7. The entire construct gets wrapped in <div class="textbox"> and </div> but for some reason the </div> is being seen as an extra close, so the page layout and formatting after that point is fubar.

    Sad sad panda. I'm going to step back and figure out how people that post blogs and non-blog sites handle all this crap. I'm starting to think I need to do my blog and associated non-blog-site on discrete instances. : (

  • xdesi
    Member
    Posted 5 years ago #

    Hi,

    So what do you actually mean here, you can retrieve your recent posts correctly, but in IE7 it is causing a break in the page layout?
    So this is obviously a CSS issue if it is working fine in FF, if you could give a link, or if not then jus click view source on your page and copy and paste the section you have added to the sidebar.

    WordPress has good CMS capabilities don't give up on it, once you get through your deisgn your site will be pretty much automated and all you have to do is post :)

    As for your feeds, I think if you used a feed management program like FeedBurner (free), I haven't used this yet but i think you can exclued categories from showing up in your feed, if this is what you want to do.

  • gregbarr23
    Member
    Posted 5 years ago #

    Yes, the custom widget is retrieving my posts correctly, but in IE7 it's causing a break in the page layout? I checked the div opens and close and they seem to match up, but apparently...not so much.

    BUT, that kinda doesn't matter because another related turned up a plugin that does just what I'm looking for with less hackery: http://wordpress.org/extend/plugins/advanced-category-excluder/

    Due to the risk of new "pages" showing up in my RSS feed, however, (fubar'd that this morning while testing a different plugin) I'm hesitant to take a single-instance approach now. I'm thinking one instance for my blog and one for my site. Maybe. Hoping to get some advice and input in this other thread specificaly about that.

  • gracieh13
    Member
    Posted 5 years ago #

    WOW! I can't believe how easy it was to add that to my sidebar. The second post in this thread from jbbrwcky worked like a charm!!!!! Thanks for saving me HOURS of time jbbrwcky!!!

  • eampiart
    Member
    Posted 5 years ago #

    anyone knows, how to show this on my homepage, so this works on my blog, but on an external page?
    i want to show this here: domain.com/index.html
    and my blog is: domain.com/blog/blog.php

    thankyou

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags