WordPress.org

Ready to get started?Download WordPress

Forums

Sidebar news widget? (12 posts)

  1. siege911
    Member
    Posted 7 years ago #

    I'm not really sure what to call what I'm looking for so I'm having trouble searching to see if it exists. But I'll describe it:

    Basically I want a widget to go in the sidebar which takes the posts from a particular category and posts them into the sidebar. Basically a "Latest News" type of thing.

    I'm also going to be posting a lot of other miscellaneous things which aren't as important so I want the "Latest News" category to stand out (hence being in the sidebar) while the other stuff just gets posted as normal.

    Does something like this exist?

  2. davidchait
    Member
    Posted 7 years ago #

    Use any RSS solution to pull your own RSS feed, from a particular category. That way it is cached, not a constant hit on the database...

    -d

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    mySQL caches queries anyway with a proper setup. Shouldn't be a big deal.

    Anyway, if you look in the widgets plugin, you'll find a function called widget_recent_entries(). It has this line in it:
    $r = new WP_Query('showposts=10');
    Change that to something like this:
    $r = new WP_Query('showposts=10&cat=37');

    Only replace the "37" with your category number. You can also change the title of "Recent Posts" to something else if you like.

  4. siege911
    Member
    Posted 7 years ago #

    The Recent Entries only give the Title. I'd prefer to have the whole text.

    Is there a way to put an RSS feed out from a single category?

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Okay then, change the widget so it displays the text of the post too.

    Find the line that says this:
    <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>

    And change it to this:
    <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a><?php the_content(); ?></li>

    BTW, yes, you can get an RSS feed for just one category. If you're using pretty permalinks, it'll be something like this:
    http://example.com/blog/category/your-category/feed/

  6. siege911
    Member
    Posted 7 years ago #

    Edit: Nevermind. My mistake. I fixed it.

    I used the Recent Entries thing however, it doesn't parse any of the bolding or italics. Is that fixable?

  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    What do you mean by "doesn't parse"? I'm not sure what you're talking about. Bolding and italics will come through just like anything else there.

  8. siege911
    Member
    Posted 7 years ago #

    Well they don't come through. None of the formatting does. Even when I want two lines between the text (i.e. new paragraph as opposed to line break), it doesn't come through.

  9. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Ummm... Are you using the_excerpt()? Or the_content()? Because yes, the_excerpt strips formatting. the_content doesn't.

  10. siege911
    Member
    Posted 7 years ago #

    I think it's something in the theme I'm using that strips it. I've tried some RSS feeds in a static page using the stylesheet from the them I'm using and if I include them in the post area, the formatting comes in fine. In the sidebar, it is all stripped.

    I'll look into it more.

  11. siege911
    Member
    Posted 7 years ago #

    I found out the problem. Just fixed the CSS and it's good to go. Thanks for all of your help.

  12. mbernolak
    Member
    Posted 6 years ago #

    As I understand as of wordpress 2.3.3 there is no widgets plugin in the "plugin" directory, widgets are part of the WP. Could anybody let me know where to look for the widget_resent_entries() function?
    I'd like to use Otto42's solution to pull posts from my news category (or any for that matter) and place it in a sidebar as a widget:

    Otto42 said above:
    "Anyway, if you look in the widgets plugin, you'll find a function called widget_recent_entries(). It has this line in it:
    $r = new WP_Query('showposts=10');
    Change that to something like this:
    $r = new WP_Query('showposts=10&cat=37');

    Only replace the "37" with your category number. You can also change the title of "Recent Posts" to something else if you like. "

    Thank you in advance for any help,
    Monika

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags