888888.888888.88""Yb..dP"Yb..8888b..Yb..dP.88b.88....db....8b....d8.88..dP""b8..dP"Y8
88__...88__...88__dP.dP...Yb..8I..Yb.YbdP..88Yb88...dPYb...88b..d88.88.dP...`".`Ybo."
88""...88""...88"Yb..Yb...dP..8I..dY..8P...88.Y88..dP__Yb..88YbdP88.88.Yb......o.`Y8b
88.....888888.88..Yb..YbodP..8888Y"..dP....88..Y8.dP""""Yb.88.YY.88.88..YboodP.8bodP'


88b.88.888888.888888.Yb........dP.dP"Yb..88""Yb.88..dP
88Yb88.88__.....88....Yb..db..dP.dP...Yb.88__dP.88odP.
88.Y88.88"".....88.....YbdPYbdP..Yb...dP.88"Yb..88"Yb.
88..Y8.888888...88......YP..YP....YbodP..88..Yb.88..Yb

January 28, 2008

Quick N Dirty

This is the fifth of my Quick N Dirty plugin posts and it is a little more involved than the previous four. It isn’t any more difficult, in fact it is a very simple plugin, but it does require adding a tag to your theme, and adding some categories to your bookmarks. None of this is difficult though so I don’t foresee many problems.

In this post I am going to show you how you can use the blogroll functionality, and a small plugin, to create a fully controllable menu for your website. Now, by fully controllable I mean that you can move items about within the menu, set the links in any way you please and choose what links you display to normal visitors and what links you display to users that are logged in.

So how do you do this? I will go through it in steps; but before I start I should mention that this may not work on versions of WordPress below 2.3.

Step 1

The first thing you need to do is to log into your blog, choose blogroll, and create two new categories. The first is a list of links that you want every visitor to see, and the second is a list of links you only want users that are logged in to your website to see. Now note down the ID of each category. (In my example 15 is for all visitors, and 16 is for logged in users)

You should now create at least one link in each. Note that in the advanced panel there is a rating option. We will use this later on.

Step 2

Before we worry about the plugin you need to insert the list into your template. To do this you need to use the template tag: wp_list_bookmarks. The example below will create a pure list, without any titles, and will order it according to the rating field that I mentioned earlier.

[php]

Notice that I have given it category 15, the category ID that is available to everyone. You need to replace this with your category ID.

Also note that the rating field only allows you to rate from 0 to 9 so if you will have more lists than this you might want to use the notes column instead.

The plugin is going to insert the links that are assigned to category 16 automatically, so when you are rating your links, if you want a member only link to appear at a given point in the list you should leave that blank in the all user list; for example, if you want the first five links to be from the all-user list, rate them 1-5 in the order you want them. If you want the sixth link to be from the logged-in-only list then find that link and rate it 6, you can then rate your next all-user link 7 to continue the list.

None of this will matter though until the plugin is added.

Step 3

The plugin uses a filter: get_bookmarks. This is called whenever a request for a list of bookmarks is put in. If the request is only for the all-user list then the plugin checks to see if the user is logged in, and if the user is logged in automatically adds the logged-in-only links to list.

Here is the plugin:

[php]
/*
Plugin Name: Quick n' Dirty Bookmark Navigation
Plugin URI: http://www.wp-fun.co.uk/2008/01/28/quick-n-dirty-bookmark-navigation/
Description: Adds a specified bookmark category to a list if the user is logged in.
Author: Andrew Rickmann
Version: 1
Author URI: http://www.wp-fun.co.uk
*/

//This is the line that adds your filter into the list.
// 'tget_bookmarks' is the name of the filter
// 'qnd_bookmark_navigation' is the name of the function, below
// 1 is the priority, 1 being highest, and 10 lowers
// 2 is the number of arguments the function expects to recieve.
add_filter( 'get_bookmarks' , 'qnd_bookmark_navigation' , 1 , 2 );

function qnd_bookmark_navigation( $bookmarks , $options ){

//first we set our category id numbers.
$normal_nav_id = '15'; //change this one to match your all-user list
$member_nav_id = '16'; //change this one to match your logged-in-only list.

//to make sure that we don't trigger an infinite loop
//if we are in the admin screen, or asking for any category(ies) except
//the all-user category we pass back the bookmarks and escape.
//The bookmarks must always be passed back or else no list will appear at all.
if ( is_admin() || $options['category'] !== $normal_nav_id ) { return $bookmarks; }

//if the user is logged in and the requested category is all-user:
if ( is_user_logged_in() && $options['category'] === $normal_nav_id ) {

//change the list options so that we are requested the additional category
$options['category'] = $normal_nav_id . ',' . $member_nav_id;

//regenerate the list with both the categories included
$bookmarks = get_bookmarks($options);

//send them on their way.
return $bookmarks;
}
}

?>

I hope it should be fairly clear what is going on in this plugin, after all it is very simple, but feel free to ask any questions you’re not sure about.

Note: If you copy the content of this plugin you will need to replace all the quote marks as WordPress replaces them with fancy ones.

Updating Code Snippets Here
Fun plugin wordpress?
no comment
page 1338
Fun With Minimalism
Sidebartabs plugin?
no comment
page 248
Write One Plugin Without Repetition Deviation Or Hesitation
Saveadminoptions wordpress?
2 comments
page 27
Updating Code Snippets Here
Wordpress fun themes?
no comment
page 1338
Html 5 Gallery
Html5 photo gallery?
6 comments
page 1305
Using Your Own Url Shortener
Htaccess shorten url?
4 comments
page 1190
Wordpress Chat
Wordpress chat?
3 comments
page 1308
Charcoal Theme Available For Wordpress
Simple charcoal wordpress themes?
2 comments
page 959
New Tabbed Widget Plugin
Tabbedwidget on wp 29?
no comment
page 333
Post Image The Easy Peasy Way
Wordpress image link anchor tag?
26 comments
page 1065
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Fun With Sidebar Tabs Styling
Image under sidebar css wordpress?
2 comments
page 336
Wordpress Chat
Wordpress chat themes?
3 comments
page 1308
Using Your Own Url Shortener
Url shortener?
4 comments
page 1190
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Wpunlimited The Ultimate Wordpress Theme
Wordpress html customisation?
3 comments
page 1141
Dont Mess With My Toot Toot
Wordpress create new post type?
16 comments
page 599
Quick N Dirty Bookmark Navigation
Dirty bookmarking links?
no comment
page 127
My Experience Of Flexx
Flexx theme review?
4 comments
page 1026
Categories Vs Tags Either Neither Or Both
Both either neither image?
12 comments
page 7
3 Ways To Speed Up Your Blog Without A Cache Plugin
Comment on speed up your blog?
one comment
page 1321
Wordpress 25 Exif Fields
Wordpress exif plugin?
12 comments
page 230
Premium Ithemes Review Photo Gallery
Ithemes reviews?
4 comments
page 226
Adding Settings To Admin Pages
Wordpress addsettingsfield?
3 comments
page 793
Updating Code Snippets Here
Fun wordpress plugins?
no comment
page 1338
How To Add Sidebars To A Theme
How to register two sidebars in wp?
10 comments
page 1053
Html 5 Gallery
Html5 image gallery?
6 comments
page 1305
Post Image The Easy Peasy Way
Wordpress theimage?
26 comments
page 1065
Using Your Own Url Shortener
Short url?
4 comments
page 1190
Using Wordpress As A Php Framework
Php framework wordpress?
2 comments
page 335
Wordpress Vs Graffiti
Html5 cms?
8 comments
page 95
Post Image The Easy Peasy Way
Wordpress medium size image link?
26 comments
page 1065
  1 query every 1664 seconds, updated 1 seconds ago.
Post a comment?