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)
How to display user’s favorites on her/his author page with her/his profile? And anyone can see
Really nice plugin.
+1 to “tracking the number of times a post is added”!
cool! i like this one so much!
Thank you so much!
I’ve been looking for something like this, FOREVER!
Love it!
If you want to see it in action (on a post):
http://s.dahoster.org/110/
In the profile:
http://s.dahoster.org/111/
Thanks again!
A life saver!
All my thought and dreams are crushed…
Ok, so I go to a post to add a favorite, I go to my profile, its there….yay.
but, when I go to another browser (w/o loging in) I don’t see any favorites.
But, when I log in again, its there.
(the two browsers are FF and IE)
So, whats the problem? & how do you store the favorites?
Shoot me an email, thanks!
The data is stored in your database and can only be retrieved if you are logged in, since the plugins has to identify which persons favorite posts should be displayed.
Ok, well.
Now I have this other problem.
I really want to show each users favorites, separately.
(On the users profile page).
Right now it shows the favorites of the user that is logged in, not the one whos profile it is.
Do you know whats going on?
With just a bit of code modification used in-conjunction with another plugin I was able to display favorites for a user to everyone on a “themed” user page.
http://www.frugalmate.com/users/admin or http://www.frugalmate.com/users/griff
I’m still working on getting everything done on the site, but I think it could work… If only I could find some time for fun projects like this!
Hey, this is an awesome plug-in. I’m not too PHP savvy but I thought I had it working for the most part until I did the display in my sidebar and got this error above my fav posts.
Warning: Missing argument 1 for mfp_display() in /my/path/to/files/atlprincess.com/html/wp-content/plugins/fav_me.php on line 152
Thanks, Kriesi! It’s a great plugin.
Now my members can add games to their favourite list
Hi, I was wondering … and this is a basic one … Do I have to create an area for my members?
Is this something like the structre I need?:
member login page,
Actual logged in page (Where I let users post articles, add to a fav list like this)
thanks
Hey Mobeego or Kriese, mind sharing how to pull this up on a per user basis like the example on frugalmate?
Great plugin, thanks!
Great, respect!
is there a way to show “who did add this post as favourite” I mean the users who added this post as favourite?
Hello Kriesi,
great plugin, thanks.
just a question: is there a way to display a thumbnail of the post with the link and title?
Hi Kriesi,
Thank you fo great plugin. My question is: can I add another bookmarking sites (Russian, Japan for exemple) to this plugin?
is there a way to show author’s favourite posts in author.php to everybody???????????
Im agree.
hey Kriesi, thank you very much for the plugin, it works damn good and i found it extremely useful for my site.
anyway, i got 1 quick question – is there some simple way to add number of comments next to the titles in favorites list? it would be just friggin perfect.
Great plugin, man! Thanks a lot!
just made a small update, plugin comes with widget support and the ability to display other persons favorite post list now
Is there a cookie version of none registered users? I would like to add this feature to my site without having to register…
Great plugin. :D
It would be nice to have an option to show separate fav list for different users. If I go to an author’s profile, I want to see his fav list, not mine. Is there any way to do this?
Thanks again.
Hi,
I tried `mfp_display(“order_by=post_title”,13); code but how can I get the author ID? I’m a newbie. Plz help. :)
I tried $author_id but it did not work.
Use the following code:
ID);
I got the code for author ID. It’s $authordata->ID
Thanks again for this nice plugin. :)
Ops. I just refreshed the page and saw your comment. Ok, I’ll add these code.
Thanks again. :D