WordPress Plugin/Widget for Must Read Posts

Today, I was looking for a simple WordPress widget that allows me to statically display links to certain posts in the sidebar. I could have used the links widget but it wasn’t flexible enough for me. My idea was to use a certain custom field of a post or page as a trigger to display it in a widget. I searched for almost an hour but I just couldn’t find any simple, widget-capable WordPress plugins that could do this?! 

In the end, I ended up writing my own widget-capable plugin. I decided to publish it so anyone else can use it on her/his blog too. The plugin’s name is “Must Read Posts”. It shows your most recommended posts and pages in a sidebar widget or in a page. As the widget’s title is editable in the WordPress Dashboard you could change it to something like “Recommended Posts”, “Important information”, “Tips & Tricks” or whatever you like.

The plugin works using a certain custom field name called must-read. If the field exists in a page or post and has the value true, the post automatically will be shown in the widget. The next image shows the plugin in action. The Must Read Posts widget is visible in the right sidebar on this theme.

must-read-posts-in-action

Once installed, you can use it with the

<?php get_mustread('Custom Title', number of posts); ?>

 
instruction in your templates or just add it as a widget to your sidebar. If you use the widget you can also specify the maximum number of posts to be shown in the widget.

must-read-widget-config

If you use the plugin for the first time, click “Add new custom field” to add a field name must-read and insert true in the value field of the page or post you want to be shown in the new widget. Once you want to display an additional post in the widget, just select it from the custom field drop-down box and insert true in the value field.

must-read-custom-field

Installation

  1. Upload must-read-posts.php to the /wp-content/plugins/ directory.
  2. Activate “Must Read Posts” through the ‘Plugins’ menu in WordPress.
  3. What to do now depends on how up to date your theme is:

Modern theme with widget support

The plugin is also a widget. If your theme supports widgets, and you have installed the widget plugin, adding the plugin to the sidebar is easy: Go to the appearance menu and drag and drop the widget into the sidebar. Don’t forget to save your new widget structure using the save button below.

Old school theme without widget support

This will require some programming in the sidebar.php file. There are many resources on the web about how to do this.

Further Customization

The look of the list of posts and pages in the widget can be customized using the style.css cascading style sheet. Just add your own or the following style to your current theme’s style.css file:

#mustread-posts li {
   list-style-type:square;
   margin-bottom:0.4em;
}

 
The plugin is available from the WordPress plugin web site: Must Read Posts Widget.

48 thoughts on “WordPress Plugin/Widget for Must Read Posts

  1. Ho, I appreciate your work, but i would like to use with conditional tags in sidebar, so that visitors can see “must read posts” only when they visit a category, or archive. I paste your code in a php sidebar widget but I have an error “Call to undefined function get_must_read()”

    What’s wrong?

  2. Matteo, you may want to try get_mustread() instead of get_must_read(), there’s an error in my documentation. The plugin/widget should be compatible to every “proper” WordPress 2.7 theme as I’m using standard WP 2.7 API calls. It may not work in pre 2.7 environments though as I’m using functions not available in versions earlier than 2.3 or 2.2.

  3. Thanks for your answer, I’m trying your plugin in WP 2.5. I made the modifcation you suggest and I notify you if it works. Thank you

  4. No luck, I’ve tried your plugin with WP 2.5 and K2 theme and is not possibile to view the sidebar widget in K2 sidebar management. Putting the code you give in a PHP widget cause an error.

  5. Matteo, the latest version (1.0.5) runs well with Exec-PHP and PHP templates in WP 2.7, I’ve just tested it. If it still doesn’t work in WP 2.5 and K2 then I don’t know why as I’m not running this environment.

  6. I cannot get changes in the “Custom field name key” box of the widget properties to stick.
    I change ‘must-read’ to my ’2008_ts’ filed name. Hit done. it is still changed if I then click edit again, but once I ‘save changes’ to the sidebar, it is reverted back to ‘must-read’ – using WP2.7, sidebar template is widgetized.

    My custom filed name change works via hard coded template calls and in posts (via exec-php) – just not within the widget …

  7. Kathy, I just tagged v1.0.6 that fixes this bug and uploaded it to the plugin repository. It should be available shortly. Please let me know if this fixes the problem for you.

  8. Hi, love what this does so far…is there a way to discover the order in which the posts are listed, and a way to change that order?

    Thanks,

    Bill Campbell

  9. Bill, at the moment the posts are unsorted. This means they appear as they are provided by the database. I understand that this is not an ideal way of handling the sort order. I’m planning to add some sort of sorting mechanism but I can’t say when it will be ready.

    Cheers,
    Jan

  10. Thanks for the great widget plug-in. I’d too like to vote for a way to modify the order. It might be easiest to do it by accepting a numeric value for the must-read field and listing the posts based on those numbers. As a user I would enter say 10,20,30, and 40 as my initial order and then I could have the flexibility to put new posts between those without re-entering all the numbers.

  11. Sorting is on it’s way, I just need some time to upload it to the plugin repository.

  12. Hi, I’m looking for an expanded version of this. I’d like to put the posts from a category onto pages instead of having to mark every post. I’d be using a customized page template so code wouldn’t be an issue.

    Have you any thoughts on how your plugin might be extended to do this?

  13. Is there a finite limit on the number of posts? I changed it from 10 to 20 and it crashed my site. Worked great until then. I use it as a widget.
    Thanks.

  14. Jeff, I just set it to 20 and and there’s absolutely nothing odd happening. You may have entered a space or character in the box accidentally. I can’t see that something like this could happen by entering just a different value.

  15. Hi Jan,

    I would like to use your code to insert whole posts on a page.
    I want it to work as if I choose must-read, the whole post should be displayed on the page.

    Do you know how I can do that?
    I tried by myself but the whole thing went totally bad.

  16. Marie, I’m afraid that I can’t give you any advice as I am not very skilled in PHP myself.

  17. Does exactly what I needed – thanks!

    It’d be nice to be able to drag the posts around in the widget to change the order, although it’s easy enough to sort the way it is now.

  18. Hi, I just want to report you about a very simple tweak I’ve done in your plugin code (just a trick #77, xDD):
    I use this plugin to suggest music listenings to my visitors. I found it very helpful but I wanted to list a random selection, not just the latest. I added a ORDER BY RAND() to the Sql envolved queries just before the LIMIT statement. This way visitors will find different suggestions each time they reload de page.

    I think It would be nice if you included a check box to automate this behaviour from the options panel.

    Thanks for this plugin!!

  19. Hi and thanx for a great plugin that I have used for a while. I have a suggestion for improvemnt though. I would like to show the latest ‘must-read’ posts and not have to change the custom field to remove old ones. Ie: if I put 5 as the limit I would like the plugin to show only the 5 latest post with the ‘must-read’ flag, sorted with the latest one on top. I guess this is a rather simple sql-thing an if I manage to tweak it myself I will let you know. Thanx again!

  20. This is an excellent plugin. I use it as a Widget. I did a little modification to the code in order to show the date of the post in the must read list.

    I would like you to help me. I would like to use it twice in my blog. Right now I am using it as “What I recommend”, but also I want to add another list like “About some theme”.

    Once I use it for the first list, it disappear from the Widgets Dashboard.

    Thanks in advance.

  21. Alejandro, I’m afraid, I don’t have a clue how to load the plugin twice. This seems to be a generic WP issue that you can’t use a plugin twice with different settings. I know some plugins have coded around this but I have no idea how it works.

    Cheers,
    Jan

  22. Hi Jan,

    I resolved it making a /must-read-posts_2 folder in /plugins, and then copy your .php into it but replacing every “mustread” to “mustread_2″.

    It is working just fine.

  23. I write some programming but I am not a PHP programmer. I am using your plugin but I have one hitch. The name of the post has the text formating showing up in the sidebar. Can you help me with some sample code to parse it out? If I could parse the string into an array and then grab the section that I need and throw it back into the correct variable..That’s what I am thinking. Suggestions?

    I need this to show up….
    Discover Muhammad Ali’s tricks for rolling with the punches

    But I am getting this…
    Discover Muhammad Ali’s tricks for rolling with the punches

  24. I love the plugin and use it on all my blogs. There is one issue though… If I use HTML in my post title like there is an issue. The br is not changed into a break but stays there just as code.

    Thanks for the awesome plugin!

  25. I use code in the title of my posts, and it shows up in the widget at my site. I gave it the name “Important Posts”.
    And I use for instance, and in the title of the post and as you can see at the website it shows like that. How do I fix this? I don’t know much about scripting.

    Can someone help?

    Thanks in Advance.

  26. Hmm didn’t show in the comment.

    I use “center” and “span” for instance in the title of my post and it shows up in the widget at the site :)

    thanks

  27. Reinaldo Aguilera (@reiaguilera)

    Hi,
    I love the plugin, I made an improvement
    change the lines 49 y 145

    $post_title = htmlspecialchars(stripslashes($post->post_title));

    for

    $post_title = strip_tags(stripslashes($post->post_title));

    Think for your next update.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>