Widget hacking : recent entries (advanced)
-
The Recent Entries Widget currently shows N most recent entries for all post categories.
I want to be able to make a styled SEPARATE widget for some of my categories, like this:
RECENT ARTICLES
* blah blah
* blah blahRECENT DIVERSIONS
* blah blah
* blah fooWhere ‘articles’ and ‘diversions’ are post categories.
I hacked widgets.php to allow me to do this, however I see no way to add another ‘recent entries’ widget to my sidebar. Only 1 is allowed.
Okay, so digging deeper, I see that certain functions need to be defined to be able to add more of a certain type of widget to a sidebar (like text and rss are allowed).
Is that the only requirement to be allowed multiple Recent Entries widgets in my sidebar? Just make my own functions as below?
wp_widget_recent_entries_setup() wp_widget_recent_entries_page() wp_widget_recent_entries_register()
-
how about instead of adding another widget, you edit the widget in question, and try to duplicate the section which outputs the relevant list of items.
You will have to hard-code the source category in the second section though.
if this is the only custom widget you use, you may want to avoid using widgets altogether and investigate “the loop” as a way to quickly and easily extract a list of posts from categories, in your sidebar.
Well, I’m trying to think larger picture here and ideally get this feature rolled seemlessly into the default WordPress widgets.php
I didn’t just hack the existing recent entries code to hardcode a single category. I made the entire widget accept a “Category:” value in the widget management screen and all.
It works perfectly, except for the “1 allowed” as I can see.
There’s no real reason for the Recent Entries widget to:
a) Not allow a category (defaulting always to all categories, but overrideable!)
b) Not be allowed multiple times on a page
There’s no real reason
Configuration is the reason, basically… by allowing that behaviour the widget author then creates the need for a config page, and a method to store that config, etc etc
otherwise he cuts out 90% or more of users who only use widgets because they are designed to avoid having to edit your template. People don’t expect to edit their widgets, if they were happy to do that, they’d just edit their templates instead.
Here’s how I changed it (part of it). Very simple. Now I just need to know the answer to my original post.
$options = get_option('widget_recent_entries'); $catname = empty($options['catname']) ? __('ALL') : $options['catname']; $title = empty($options['title']) ? __('Recent Posts') : $options['title'];…
if ($catname == "ALL") $r = new WP_Query("showposts=$number&what_to_show=posts&nopaging =0&post_status=publish"); else $r = new WP_Query("category_name=$catname&showposts=$number&what _to_show=posts&nopaging=0&post_status=publish");There already is a config page for this widget.
I think you know what I am talking about, but your comment about a ‘Configuration Page’ above makes me think not. Let’s also be clear here – I am not talking about a plugin. This is a widget in widgets.php.
It requires only simple params in the pop-up box when you access the widget’s controls to enter parameters.
As delivered it accepts ‘Title’ and ‘Number of posts to show’
I merely added ‘Category’ to those options and it works exactly how I envisioned.
I simply need to know (or merely confirmation of) what needs to be done in order to allow several of these widgets per sidebar, just like the ‘Text’ and ‘RSS’ widgets allow.
that popup you describe is basically a config page… and the issue is that when you duplicate something, all of the variable names populated with information for Widget1, are now being duplicated for Widget2 – depending on how it’s written, this could be fatal.
Let me see if I can give you an analogy… I have two identical cups in my hands, both with the Starbucks logo on them. One has tea in it, and the other has coffee.
Pick which one is yours just by looking at them.
Life is much easier when there’s only one cup, right? – and when there are two, then you must differentiate between them somehow..
the text and RSS as you mention do not allow an unlimited number of widgets… its simply a case of having more than one out of the box – which means it was designed from the beginning to allow two. If you look closely they don’t each have the same name, and hence they’re built not to have the same configuration either.
Well, I got it working, then saw what you’re talking about. The same configuration was used for every ‘Recent Posts’ widget I added and I could not change it.
Bummed.
I guess I have to do it the dumb way.
this may help:
http://wordpress.org/extend/plugins/category-posts/
The topic ‘Widget hacking : recent entries (advanced)’ is closed to new replies.