Facebook fanbox wordpress plugin

It’s just a simple fanbox widget as wordpress plugin, nothing to explain. But I made my own version ?

Features

  • iframe method
  • auto detect ie(internet explorer), because sometimes it’s make problem for ie and option to use as iframe only for ie !
  • jquery based document ready facebook load ! Not clear ? see bellow

One thing to note that I used a way to load the facebook js script after loading jquery as normally in wordpress site front end we use jquery and many plugin uses this… so we can take that jquery is using default. So I loaded the fb js using wp_enqueue function and then called the fb init function after the document is loaded using jquery dom ready function 😛 … It’s just an experiment about slow loading of facebook fanbox widget in wordpress 😀

Download

[download id=”23″]

If you just download with no comment and no recommendation to others, then I am planning to hate you 😛
Man at least share in social network and give me traffic so that I can have more money from ads 🙁

Good morning. It’s just morning after working whole night and I am feeling too hungry 🙂
Continue reading

Fix wp plugin “Post and Page Excerpt Widgets” not to break conditional tag

Post and Page Excerpt Widgets is a nice plugin to show post/page excerpt as as widget in sidebar position. You can download it from wp code from here. One I thing I noticed about this plugin is it has a common bug that I faced many times while using query_posts. When I use this query_posts it’s break some conditional loop like is_home(), is_category() etc but there is another function get_posts in wordpress that does the same thing but don’t have similar problem. Once I discussed about this problem in one of my old posts. Please check that posts for better sense from here is_home-is_single-is_category-is-not-working-in-wp!.

Let me focus to this writing again 😀
As Post and Page Excerpt Widgets is using the query_posts function for custom query it make’s problem for conditional tags. Let me show u solution and it’s like my that posts.
In you theme functions.php add a new function if not exists yet

Continue reading

Send ajax request in wordpress using wpnonce

wpsecuritythumblet’s send ajax request in wordpress using wpnonce

Hei, I am not going to discuss what is wpnonce and why you should use this in your plugin or how important to use this to secure your plugin 😛
But here I am going to discuss how you can use wpnonce in ajax request, I mean if your plugin handles ajax request.
Steps that we need to follow are:

One: Create wpnonce value.
Two: Send wpnonce value as an extra parameter with ajax requestion
Three: Check ajax referrer with the wpnonce value that was created in step one and sent in step two.

Ok, how to create a wpnonce value ?
we need to use wordpress function wp_create_nonce() . See wordpress codex here.
< ?php $my_wpnonce= wp_create_nonce (‘you-look-nice’); ?> // “you-look-nice” is just a string, u can use whatever u want. here $my_wpnonce will get a hash from wp_create_nonce. Oh that is not direct hash of “you-look-nice” but based on user id, time and that string. To know more about this function please check pluggable.php in wp-includes folder

Now send wpnonce value $my_wpnonce as an extra parameter while seding ajax req. Continue reading

āĻ“ā§ŸāĻžāĻ°ā§āĻĄ āĻĒā§āϰ⧇āϏ āϟāĻŋāĻĒā§āϏ-ā§Š

āϝāĻžāϰāĻž āĻāχ āϏāĻŋāϰāĻŋāĻœā§‡āϰ āφāϗ⧇āϰ āĻĻ⧁āχāϟāĻž āĻĒā§‹āĻ¸ā§āϟ āĻĒāĻĄāĻŧ⧇āύāύāĻŋ āϤāĻžāĻĻ⧇āϰ āϜāĻ¨ā§āϝāσ
āĻ“āϝāĻŧāĻžāĻ°ā§āĻĄ āĻĒā§āϰ⧇āϏ āϟāĻŋāĻĒā§āϏ-ā§§(āφāĻŽāĻžāϰ āĻŦā§āϝāĻ•ā§āϤāĻŋāĻ—āϤ āĻŦā§āϞāϗ⧇)
āĻ“āϝāĻŧāĻžāĻ°ā§āĻĄ āĻĒā§āϰ⧇āϏ āϟāĻŋāĻĒā§āϏ-⧍(āφāĻŽāĻžāϰ āĻŦā§āϝāĻ•ā§āϤāĻŋāĻ—āϤ āĻŦā§āϞāϗ⧇)

āĻ“āϕ⧇ āϤāĻžāĻšāϞ⧇ āφāϜāϕ⧇āϰ āϟāĻŋāĻĒā§āϏ āĻļ⧁āϰ⧁ āĻ•āϰāĻž āϝāĻžāĻ•āĨ¤ āĻāϰ āφāϗ⧇ āϞāĻŋāϖ⧇āĻ›āĻŋāϞāĻžāĻŽ āĻ•āĻŋāĻ­āĻžāĻŦ⧇ āĻ“āϝāĻŧāĻžāĻ°ā§āĻĄāĻĒā§āϰ⧇āϏ āĻ•āĻžāĻ¸ā§āϟāĻŽ āĻĒ⧇āϜ āϤ⧈āϰāĻŋ āĻ•āϰāĻž āϝāĻžāϝāĻŧ āϝāĻž āĻ›āĻŋāϞ⧋ āĻ•āĻžāĻ¸ā§āϟāĻŽ āĻŸā§‡āĻŽāĻĒā§āϞ⧇āϟ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧇āĨ¤ āĻ•āĻŋāĻ¨ā§āϤ⧁ āĻāĻ•āĻ¤ā§āϰ⧇ āϝāĻž āĻšāϝāĻŧ āĻĒāĻžāϤāĻžāϟāĻž āĻ“āϝāĻŧāĻžāĻ°ā§āĻĄ āĻĒā§āϰ⧇āϏ⧇āϰ āĻĄāĻžāϟāĻžāĻŦ⧇āϜ āĻĨ⧇āϕ⧇ āφāϏ⧇, āĻŽāĻžāύ⧇ āĻĒāĻžāϤāĻžāϰ āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟāĨ¤ āĻ•āĻŋāĻ¨ā§āϤ⧁ āϝāĻĻāĻŋ āĻāĻŽāύ āϚāĻžāχ āϝ⧇ āĻāĻ•āϟāĻž āĻ¸ā§āĻŸā§āϝāĻžāϟāĻŋāĻ• āĻĒāĻžāϤāĻž āĻšāĻŦ⧇ āĻ•āĻŋāĻ¨ā§āϤ⧁ āĻ“āϝāĻŧāĻžāĻ°ā§āĻĄ āĻĒā§āϰ⧇āϏ⧇āϰ āϭ⧇āϤāϰ⧇ āĻĨ⧇āϕ⧇ āĻāĻŦāĻ‚ āϐ āĻĒāĻžāϤāĻžāϝāĻŧ āĻ“āϝāĻŧāĻžāĻ°ā§āĻĄ āĻĒā§āϰ⧇āϏ⧇āϰ āϝāĻžāĻŦāϤ⧀āϝāĻŧ āĻŸā§‡āĻŽāĻĒā§āϞ⧇āϟ āĻŸā§āϝāĻžāĻ— āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻž āϝāĻžāĻŦ⧇āĨ¤ āϧāϰ⧁āύ āφāĻĒāύāĻŋ āĻ“āϝāĻŧāĻžāĻ°ā§āĻĄ āĻĒā§āϰ⧇āϏ āχāύāĻ¸ā§āϟāϞ⧇āĻļāύ⧇āϰ āϰ⧁āϟ āĻĄāĻŋāϰ⧇āĻ•ā§āϟāϰ⧀āϤ⧇ āĻāĻ•āϟāĻž āĻĢā§‹āĻ˛ā§āĻĄāĻžāϰ āĻŦāĻžāύāĻžāϞ⧇āύ āϝāĻžāϰ āύāĻžāĻŽ myfolder. āϤāĻžāĻšāϞ⧇ āĻāχ āĻĄāĻŋāϰ⧇āĻ•ā§āϟāϰ⧀āϰ āϞāĻŋāĻ™ā§āĻ• āĻšāĻŦ⧇ http://yoursite.com/myfolder āĻĻ⧇āϖ⧁āύ āĻāϟāĻž āĻ•āĻŋāĻ¨ā§āϤ⧁ āĻ“āϝāĻŧāĻžāĻ°ā§āĻĄ āĻĒā§āϰ⧇āϏ⧇āϰ āĻĢā§‹āĻ˛ā§āĻĄāĻžāϰ āύāϝāĻŧāĨ¤
āĻāĻ–āύ āĻāχ āĻĢā§‹āĻ˛ā§āĻĄāĻžāϰ⧇ āĻāĻ•āϟāĻž php āĻĢāĻžāχāϞ⧇ āϤ⧈āϰāĻŋ āĻ•āϰ⧁āύāĨ¤ āϧāϰ⧁āύ myfile.phpāĨ¤
āĻĢāĻžāχāϞ⧇āϰ āĻļ⧁āϰ⧁āϤ⧇āχ āϞāĻŋāϖ⧁āύ āĻāχ āϰāĻ•āĻŽāσ

[code language=”php”]< ?php
define(‘WP_USE_THEMES’, false);
require( dirname(__FILE__) .’/../wp-blog-header.php’);
?>[/code]

āϝāĻĻāĻŋ myfile.php āĻāĻ•āĻĻāĻŽ āϰ⧁āĻŸā§‡ āϰāĻžāϖ⧇āύ āϤāĻžāĻšāϞ⧇

[code language=”php”]< ?php
define(‘WP_USE_THEMES’, false);
require( dirname(__FILE__) .’/wp-blog-header.php’);
?>[/code]

Continue reading

Adding no follow for links in wp comments

Don't Follow MeOne of my senior brother just asked me, how to add no follow rel for comments in wordpress. May be there is plugin for this. Look to my code 🙂
How to use:
1.Open the functions.php file in ur current theme and put these code within php tags.

What it will do:
1. Will add ‘no follow’ as rel in url , if comment contains any url.
2. Will ad ‘external’ as rel in url , if comment contains any url.
3. Will add target=”_blank” in comment author’s url so that their web url open’s in new window/new tab as in browser settings
4. Will add target=”_blank” to url, if comment contains any url
5. Wp adds ‘no follow’, ‘external’ rel in comment author’s url by default. So we don’t need to add this 😛

Tips:
1.If possible upgrade to wp2.8.2

[code language=”php”]
function nofollow($text) {
$text = preg_replace(‘/<a /i’,'<a rel="nofollow external" ‘,$text);
$text = preg_replace(‘/<a /i’,'<a target="_blank" ‘,$text);
return $text;
}
function targetblank($text){
$text = preg_replace(‘/<a /i’,'<a target="_blank" ‘,$text);
return $text;
}

add_filter(‘comment_text’, ‘nofollow’);
add_filter(‘get_comment_author_link’,’targetblank’);
[/code]

any question ask me 🙂
p.s.: post image is just for fun 😛

BTW, are you afraid of editing your functions.php ? Ok, no problem you can add the above piece of code using the bellow wp plugin.
[download id=”9″]

Duh, you are totally unhappy with this post, na ? You can to treat your commentors with “cake and cook”, ok no problem.Just forget my post and read this blog post …“The Single, Most Profound Way To Thank Your Commenters”.
Happy now ?

How to use timthumb in WP MU

I think to show the first image as thumb in wp front page or blog layout is very common for any theme. But to use it in wordpress mu version is not direct or need to do some hack or modify the normall process of adding timthub. Normally we upload images from wp media manager and use those in posts. In normal wordpress the upload dir is wp-content/uploads and files and images are uploaded to that directory. In wordpress mu version files are uploaded by user basis folder and for this wp-content/blogs.dir/userid is the uploaded dir for any image. here user id is named as folder name for each user. then wp-content/blogs.dir/userid/files. But when u browse the site the image link format is like http://yoursitename/files/year/month/image name but format is reshaped by the wp mu htacces which real physical path is like wp-content/blogs.dir/userid/files/year/month/image name.
Continue reading

How to make menu like news.bbc.co.uk

bbcNow a days I am a great fan of wordpress. Recently I have done some projects on wordpress and getting expert day by day 😛 heh heh.

This post about how can we make menu in wordpress like news.bbc.co.uk. Now a days some clients want clone sites. They don’t think about all the functionality but the look and feel clone 🙂 .
So to clone the menu like news.bbc.co.uk we what we need:
1. wp function wp_list_categories(args)
2. CSS to give look and feel like news.bbc.co.uk

Before we start let’s check what we are going to do:
here is the image that we are going to make or the menu that we are doing to make using wp_list_categories function and css. Look this menu is 2 level deep. To keep the theme clean u can make a function in functions.php file like bellow and just call the function in theme where u want to place the menu.
Look here we are using echo= 0 as want to just return the output from this function. and depth =2 as we want to make two level hirarachyâ€Ļ check others params that I have used. To know details about the template tag wp_list_categories pls check this page in wp codex.

Now what we need is to apply the css to style the menu like news.bbc.co.ukâ€Ļ one thing to keep in mind. When u will browse through the category I mean u click the any category from the menu and posts will be shown using category.php template then active category will get an extra class automatic which is helpfull to highlight using css but if u browse any single.
[code=’php’]function get_leftcatmenu(){
$excludecats = array();
$excludecats = array(1,2,3); //categories to exlclude
//or
//$includecats = array ();
//$includecats = array(1,2,3); //categories to include

/*
// same thing can be done using a simple plugin and saving the categories in option table , bellow code is for comma seperated cat list
$excludecats = explode(‘,’, get_option(‘bbcnews_leftmenucid’));
$excludecats = implode( “,”,$excludecats);
*/
/*
$includecats = explode(‘,’, get_option(‘bbcnews_leftmenuscid’));
$includecats = implode( “,”,$seccats);

//sample code to exclude
return wp_list_categories(‘orderby=name&amp;amp;style=list&amp;amp;hide_empty=0&amp;amp;show_count=0&amp;amp;title_li=&amp;amp;exclude=’.$excludecats.’&amp;amp;hierarchical=true&amp;amp;depth=2&amp;amp;echo=0′);

// sample code to inlclude
return wp_list_categories(‘orderby=id&amp;amp;style=list&amp;amp;hide_empty=0&amp;amp;show_count=0&amp;amp;title_li=&amp;amp;include=’.$includecats.’&amp;amp;hierarchical=true&amp;amp;depth=2&amp;amp;echo=0′);
*/
}
[/code]
post we need the hightlight the category in the menu to which the single post belongs to. But to make this happen that adding an extra class to the menu to make active while browsing any single posts I have used a plugin 🙂 named “Show Active Category (while browsing a post)“. Note if any post belongs to more one category then it will add extra active class to each category.

Uffâ€Ļ.now check the css code that I used:
Note: this css code works fine in ff3 and ie6 and I have no interest with other browser at this moment.
Code to use in theme:
[code=’php’]

  • home”>

is_home-is_single-is_category-is-not-working-in-wp!

If u are reached here using search engine then I am sure that you are just fucked up 🙁 .. is_home(), is_single(), is_category() are not workingâ€Ļspecially in footer and other places. I faced the same problem. While working with a wordpress theme, this functions were working fine in footer but once I noticed that they are not working as they should be !â€Ļ.

Let me explain why and how this problem occurs and what’s the solution :

I think if u are familiar with the famus LOOP in wordpress. The following is_home(), is_single(), is_category() functions depends on the loop. ACtually when u visit the home page then header.php, index.php, sidebar.php and footer.php files are executed and in the same way when u visit a single post then normally header.php, single.php, sidebar.php and footer.php files are executed. Actually some global page specific query is done for single.php, index.php etc. is_home(), is_single(), is_category() they will work fine if u use the default theme and don’t add any custom query !

Let’s check the code for is_home() function â€Ļ
[code=’php’]/**
* Whether current page view is the blog homepage.
*
* @since 1.5.0
* @uses $wp_query
*
* @return bool True if blog view homepage.
*/
function is_home () {
global $wp_query;
return $wp_query->is_home;
}
[/code]
Ok, for custom query maximum time I use this function get_posts. But to get more control I used query_posts. They are same and share some common arguments but query_posts gives more controls and more arguments to pass to get the exact query. Now Let’s check the code for query_posts() function

[code=’php’]/**
* Setup the Loop based on the query variables.
*
* @uses WP::$query_vars
* @since 2.0.0
*/
function query_posts() {
global $wp_the_query;
$this->build_query_string();
$wp_the_query->query($this->query_vars);
}
[/code]

and code for get_posts

[code=’php’]/**
* Retrieve list of latest posts or posts matching criteria.
*
* The defaults are as follows:
* ‘numberposts’ – Default is 5. Total number of posts to retrieve.
* ‘offset’ – Default is 0. See {@link WP_Query::query()} for more.
* ‘category’ – What category to pull the posts from.
* ‘orderby’ – Default is ‘post_date’. How to order the posts.
* ‘order’ – Default is ‘DESC’. The order to retrieve the posts.
* ‘include’ – See {@link WP_Query::query()} for more.
* ‘exclude’ – See {@link WP_Query::query()} for more.
* ‘meta_key’ – See {@link WP_Query::query()} for more.
* ‘meta_value’ – See {@link WP_Query::query()} for more.
* ‘post_type’ – Default is ‘post’. Can be ‘page’, or ‘attachment’ to name a few.
* ‘post_parent’ – The parent of the post or post type.
* ‘post_status’ – Default is ‘published’. Post status to retrieve.
*
* @since 1.2.0
* @uses $wpdb
* @uses WP_Query::query() See for more default arguments and information.
* @link http://codex.wordpress.org/Template_Tags/get_posts
*
* @param array $args Optional. Override defaults.
* @return array List of posts.
*/
function get_posts($args = null) {
$defaults = array(
‘numberposts’ => 5, ‘offset’ => 0,
‘category’ => 0, ‘orderby’ => ‘post_date’,
‘order’ => ‘DESC’, ‘include’ => ”,
‘exclude’ => ”, ‘meta_key’ => ”,
‘meta_value’ =>”, ‘post_type’ => ‘post’,
‘suppress_filters’ => true
);

$r = wp_parse_args( $args, $defaults );
if ( empty( $r[‘post_status’] ) )
$r[‘post_status’] = ( ‘attachment’ == $r[‘post_type’] ) ? ‘inherit’ : ‘publish’;
if ( ! empty($r[‘numberposts’]) )
$r[‘posts_per_page’] = $r[‘numberposts’];
if ( ! empty($r[‘category’]) )
$r[‘cat’] = $r[‘category’];
if ( ! empty($r[‘include’]) ) {
$incposts = preg_split(‘/[\s,]+/’,$r[‘include’]);
$r[‘posts_per_page’] = count($incposts); // only the number of posts included
$r[‘post__in’] = $incposts;
} elseif ( ! empty($r[‘exclude’]) )
$r[‘post__not_in’] = preg_split(‘/[\s,]+/’,$r[‘exclude’]);

$r[‘caller_get_posts’] = true;

$get_posts = new WP_Query;
return $get_posts->query($r);

}
[/code]

get_posts will not make any problem for is_single(), is_home(), is_category() etc functions.

Solution: To avoid this problem you can use this trick:

[code=’php’]$query_backup = clone($GLOBALS[‘wp_query’]); //keep backup
……
query_posts(…..)

$GLOBALS[‘wp_query’] = $query_backup; //restore from backup
[/code]

Further info: Please keep in mind that the php function clone() will not work in php4, it’s just for php5 becuase Php5 handles objects in different way. Like in php5 you can copy a object in this way
$new_object = clone ($old_object);
here $new_object will not copy the object actually though it will just point to $old_object but in php4 the thing is just copy like bellow.
$new_object = $old_object;

You can check this link for better explanation.

Sometimes pain gives us a way to think 😛

thanks