in Tips and Tricks, WordPress, Wordpress Plugin

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

[code language=”php”]
function php4_clone($object) {
if (version_compare(phpversion(), ‘5.0’) < 0) {
return $object;
} else {
return @clone($object);

Now open the plugin file page-and-post-excerpt-widgets.php and search for string “query_posts”. I think you should find matching in two places. Let’s take care of them now.
before that line query_posts(‘page_id=’.$page_ID);
add this line

[code language=”php”]
$query_backup = php4_clone($GLOBALS[‘wp_query’]);

and after the while look that means
after this line endwhile; add

[code language=”php”]
$GLOBALS[‘wp_query’] = $query_backup;

Do same thing for both matching. That will save u for not breaking any conditional tags like is_home() etc in your theme. I think wordpress should include such seucurity in core query_posts function so that it does not break the default wordpress’s The Loop.

Sometimes I can not find that why wordpress conditional tag is not working in my theme and that makes me really crazy !

Guys if you find this post help full then please take care the large social bookmark icon bellow 😀