WordPress Plugin: My favorite posts
“My favorite posts” is a WordPress plugin which allows logged in users to add posts they like to a private favorite post list.
This post will teach you how to use the plugin.
Current Version: 1.2
Last Update: October 10th 2008
Download
First of all you need do download the zip file, unzip it and place the fav_me.php file at your server at /wp-content/plugins/.
Last Update: October 10th 2008, Version: 1.2
Installation
Installation is rather easy: just activate the plugin, it will create the database table it needs to work on its own.
Using the Plugin
We leave the no-brainer part to learn something interesting now: how to implement the plugin in your theme.
Basically all you need are 2 functions:
- mfp_the_link();
- mfp_display();
mfp_the_link will display an “Add this post to your favorite post list” link wherever you call it. Best practice of course is to add the function anywhere INSIDE your WordPress loop. That will create the add link for each post.
You can pass up to two parameters when calling mfp_the_link().
These are: add_link and remove_link.
The syntax is euqal to many wordpress core functions:
mfp_the_link("add_link=add me please&remove_link=remove me please");
This will replace the default link names with the ones you provide. If you want you can add markup as well:
mfp_the_link("add_link=<span class='add_this'>add me please</span>");
mfp_display will display the list of favorite posts anywhere you like. No WordPress loop required here.
So you can put the list in your sidebar, footer, main content area etc.
Of course you can pass parameters here as well. Calling the function without parameters will create an unordered list: each list item will contain a link to the post and a “remove link”.
The default classes added are:
- ul class: mfp_favorites
- link class: mfp_link
- remove link class: mfp_remove_link
So you don’t like my classes? Or you want to display the items in <div> and <p> instead of <ul> and <li>?
Here are the parameters you may change:
- title : Default is no title
- display : Default is “list” -> you may change it to “div”
- remove_link : Text for remove link, Default is “remove”
- class : Class for ul/div , defaul is “mfp_favorites”
- link_class : Class for the post link, default is “mfp_link”
- remove_link_class : Class for remove link, default is “mfp_remove_link”
- order_by : Order of items, default is ID, you can change that to any field name of the wp_posts table: some examples would be “post_title”, “post_author”, “post_date”. Get the full list at the WordPress Codex.
Some examples:
// Add a h3 title mfp_display("title=<h3>Favorite Posts</h3>") // Display as Div with different class names mfp_display("display=div&class=class_1&link_class=class_2"); // Order by post Title & different remove link text mfp_display("order_by=post_title&remove_link=up up and away");
Another option is to pass the ID of a user to the function. This way it will display another users favorite post list. you can do that by apending the ID as a seperate parameter. The following example would retrieve the posts of user 13 from the database:
mfp_display("order_by=post_title",13);
One of the best options to use this function would be to show it on the authors page of a user. Just insert the ID of the user dynamically ;)
Another option to display the posts is through the widget added in version 1.2.
Thats it. If you encounter any problems, please tell me via contact form or comments. I would also be glad to hear suggestions for improvements, be it in functionality, usability or code wise.
Have a nice day ;)
Version History:
v.1.0: 03.06.2008
v.1.1: 04.06.2008 (major code change, increased flexibility)
v.1.1.1: 10.06.2008 (minor bug fix: broken <a/> tag & php notice)
v.1.2: 10.08.2008 (added widget support and possibility to display other peoples favorite posts)
Hi Kriesi,
The fav list shows only the post title. Is it possible to add post author as well?
For example:
My daily life – Auhtor X
WP Plugins – Author Y
Hi I love this plugin. Thank you. I am not a coder and would like to know if anybody can tell the code for replacing the text for ‘add’ or ‘remove’ with a graphic.
very great plugins for wordpresss
Awesome plugin. Thanks!
Hi! Very nice plugin and i am able to use it. But now i need some modification. I ma creating new model website and in every model post there is his profile photo. So, while displaying the favorite model, i want to display their photo and the link. But till now, i am only being able to display the title and link.
Hope to receive your reply soon.
thanks,
sakin
I own a single authored blog so my need would be the ability to favorite some posts to be then shown to the public. There was the old noteworthy but doesn’t work and sajid’s favourite post ain’t working too. So yours is the single one similar, but actually lacks the public displaying. Do you think you’re gonna add the feature or maybe I can try to hack yours someway myself?
Thanks. :-)
PS. And maybe also have the ability to show that a post is favorited not only in the side, but directly in the post, with a custom image, a star, for example. Ain’t a good idea? :-)
this feature is already implemented. if you would like to display the list of a specific user, just append the id of that user:
mfp_display(“order_by=post_title”,1);
This would always display the favorite post list of the admin
Edit: you can display this list everywhere, just read the instruction above ;) Adding a little star can easily be done with css since each link get a specific class.
here is an example of the favorite post list on the authors page:
Communizine Theme
Ops, sorry, didn’t get that id would work also for non-registered users. Thanks a lot! :-)
Hi Krisei,
about the second thing, I was meaning something slightly different: don’t want to display a list somewhere else, just that a post is a favorited one, so it would be something like the thing implemented on mfp_display, but on mfp_the_link function. Adding a show parameter that, if the user ain’t logged*, if show is true, if the post is a favorited one, echoes some div classed htmlbunch, so you can put in text or img.
*or maybe, intended for multiusers blogs, a more sophisticated thing like if true and the user ain’t the author, something like:
div.class1(htmlbunch a.class2(author))
What about? Do not tell me that this is already implemented or I’m a dumbass! :-)
hi there!
I made with photoshop animated myspace banners.
take a look at them:
http://tinyurl.com/5ajypv
Thank you 4 your site :-) xoxo
Here I am, again.
Got an XHTML validation error Krisei. It’s in the if user in the foreach loop that displays the list. That part of code isn’t displayed for non logged users (as a validator website) so the closing tag of the entry of the list (or paragraph if div is chosen) is missing. You have to put out of that if the $entry_after:
$fav_post .=$entry_before;
if(…){$fav_post .=…}
$fav_post .=$entry_after;
Now valid. :-)
The plugin works great and Im using it on 1.6.5 wordpress. I have a question though, can this plugin be modiefied with ajax to spice the effects when adding to favorites without refreshing the page and same for removing favorites ? ANYBODY ?
Awesome plugin!
Just a quick Q. Is there a way to display a message in the event that the user hasn’t signed in yet? Right now it just appears blank.
Thanks!
hi kriesi,
I congratulate you for the plugin, I am using it on my site. As you can see in action in juanis’s page
Two questions:
You can show users who have the same post as a favorite in the sidebar? or users who have marked as a favorite to post the same mine in the author page?
Greetz from Argentina
Juani
Excellent plugin, I congratulate you.
Thank you very much was looking for something like this.
But I agree with the question that Matt iso up.
Is there a way to display a message in the event that the user has not signed in yet?
Happy new year
I think looking to find an answer
http://codex.wordpress.org/Function_Reference/is_user_logged_in
Thanks
Great plugin. I’ve been looking for something like this for a long time.
I’m using it on my photography store site. Of course everyone has to have some little feature they’d like. For me, it would be to easily show thumbnails in what I call the Wishlist.
P.S. I would like to contribute a few bucks through Paypal for your work on this. Where can I send it.
Best — Dave Beckerman
Super Plugin!!
Does it work with WordPress 2.7 ???
Thanks
Is there a way to display the posts in the users dashboard?
thank you so much for this! exactly what i was looking for… did the trick and totally painless.
would be nice to be able to output the most popular posts for a specific time period, but of course… not necessary.
Hi! Thank you for the plugin.
One question. This plugin display de fav list of the logged user but… how can I get the fav list of the author page user?? I always get my fav list also if I visit another user page…
Thanks!
Is there a way to have the displayed favorites look like the original post so that it shows the title, date, post, etc… exactly the same way you have it set up in your theme?