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/.

Download(Removed)
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:

  1. mfp_the_link();
  2. 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)

Attention

This WordPress Theme was discontinued and is no longer available for sale

Tags: ,
165 replies
Newer Comments »
  1. Paulo Faustino
    Paulo Faustino says:

    Hello Kriesi.

    I’m getting a little problem.
    I uploaded the plugin and activated it. How can i call it to my singlepost.php for example? I want to show it in the end of each post but i can’t get it.

    The same for that sidebar show off list.

    Can you help please?

    Regards,
    Paulo

  2. Kriesi
    Kriesi says:

    Thanks for the kind words, hope the plugin serves all of you well.

    @ adonis: without the login its hard to identify the user and therefore nearly impossible to display the list stored in the database. Only solution I could think of is using cookies to store the data instead of the database, but this would somehow limit the usefulness of the plugin.

    Accessing the list from more than one computer would be impossible and whenever the cookie would be deleted the list would be gone as well.

    @Paulo: If you want to display the add post link on a single page just write the function call mfp_the_link() in your templates single.php.

    And to display the whole list in your sidebar, just place the function call mfp_display() in your sidebar.

  3. Mobeego
    Mobeego says:

    Great plugin! I used the is user logged in function in wordpress to display a link that displays to the user that they must login to add to favorite. :) Thanks!

  4. Frank
    Frank says:

    I cannot get this to work for non-admins. It works perfectly fine when i’m logged in as an admin, but when I log in as a subscriber, [level 0] it doesn’t show the ‘Add this to my favorite posts’ link. Any ideas why?

  5. Kriesi
    Kriesi says:

    Hey Frank,
    A am afraid, I have no Idea why this problem occurs at your website, since the plugin works fine on every blog I testet it.

    Only reason I could think of is another plugin that changes user permissions. What you could try is deactivate all other plugins and see if the link is displayed then.

    btw: you got a nice website, i just started watching heroes and love it. Watched Season 1 in a marathon session of 2 days ;D

  6. Matt
    Matt says:

    Great plugin… thanks Kreisi!

    The add/remove works great but when I went to put the favorites code I get a php syntax error…

    Parse error: syntax error, unexpected ‘=’ in /home/*******/public_html/wp-content/themes/sgrl/single.php on line 12

    using code

    It only appears to error when calling mfp_display. I run the latest version of wordpress. any ideas or suggestions?

    Thanks again :)

  7. Matt
    Matt says:

    … comment strip the php code…

    mfp_display(”display=div&class=class_1&link_class=class_2″);

    -or-

    mfp_display(”order_by=post_title&remove_link=up up and away”);

  8. Kriesi
    Kriesi says:

    I think the problems are the double quotes. its a strange thing, but WordPress keeps changing them into fancy quote-like characters when I write articles, even if I use the html code. If you don’t copy paste the code and instead write it by hand you shouldn’t get any errors.

  9. Chuck
    Chuck says:

    Thank you so much for the plugin. I love it!

    Question for you. When I’m on a page with multiple posts and I favorite a post towards the bottom. The page refreshes and goes to the top. Is there away to anchor the post?

    Thanks again!

  10. Kriesi
    Kriesi says:

    Hi Chuck,

    I can add this to the to-do list for the next version, seems like a pretty good idea. If you want it here and now, its rather easy to accomplish. Lets say your WordPress loop automatically generates the anchors for each post (id=”post-1″, id=”post-2″ etc) as most themes do. Just open the fav_me.php file, and check line 84 and 86. These lines create the add and remove links.

    Just change favorite-post=$post_ID to favorite-post=$post_ID#post-$post_ID

    same for the second link, and an anchor is added to each add and remove link.

  11. Chuck
    Chuck says:

    Thanks so much! I just made the changes, works perfectly. BTW, here’s the site that I’m using your plugin…

    http://foodgawker.com/

    One odd thing, when I tried to float:right the add and remove link span or div, the image wasn’t clickable in IE, worked fine in FF and Safari. I could see the link in the bottom of the browser on rollover, but couldn’t click it. I had to push it right using padding… very odd. But it’s either my issue or just typical IE bug. Thanks again.

  12. gMk
    gMk says:

    Very nice work.

    Be great if you could get a count of the number of times a post has been made a favourite by all users.

  13. Cool Raker
    Cool Raker says:

    Great plugin, I’m using it at my newly launched site http://coolraker.com as a kind of personal wish list of a reader’s favorite items. I also second the request for tracking the number of times a post is added, that would be very useful.

Trackbacks & Pingbacks

  1. […] Muhterem arkadaþlar wordpress için çok güzel bir eklenti olduðunu düþündüðüm "my favorite posts" (favori-popüler yazýlar) eklentisini kurmak istiyorum ama beceremedim bir türlü. Aynen […]

  2. […] download (the plugin currently contains two minor bugs, see end of this post for a quick fixed version), […]

  3. […] WordPress Plugin: My favorite posts | Kriesi.at – new media design “My favorite posts” is a WordPress plugin which allows logged in users to add posts they like to a favorite post list. (tags: wordpress plugin) […]

  4. […] My favorite posts es un plugin para WordPress que te permite almacenar dentro de una categoría especial, aquellas entradas que los usuarios logeados han marcado como favoritas. […]

  5. […] posts favoritos, plugin para WordPress 5 06 2008 My favorites posts, es un plugin para WordPress que te permite tener un listado de posts considerados como […]

  6. […] My favorites posts, es un plugin para WordPress que te permite tener un listado de posts considerados como favoritos. […]

  7. […] Learn more about his new plug-in and how it works, or download it from here. […]

Newer Comments »

Comments are closed.