How to get Custom WP_Query Loop Working with Pagination and WP-PageNavi

Update May 6th, 2011: This article is now outdated, please read this one instead for a more updated way get your custom query working with pagination and PageNavi.

For this current redesign of wplover (have you seen it? come take a look!) I’m using a custom loop in the index page to remove all posts under “Links” category from the main content area. Now the most common problem with WP_Query-based custom loops is that it screws up pagination. No problem, we have this WBLT post to the rescue, and now my code looks like this:

<?php
  $temp = $wp_query;
  $wp_query= null;
  $wp_query = new WP_Query('cat=-6&paged=' . $paged); // don't show posts from category ID 6, a.k.a Links
  while ($wp_query->have_posts()) : $wp_query->the_post();
?>
 
<?php // the usual post-displaying codes here ?>
 
<?php
  endwhile;
  $wp_query = null; $wp_query = $temp; ?>

One more thing to add is that I’m also using the WP-PageNavi plugin to show custom page navigation after the posts. After messing around with the code a bit, I find that to get the plugin working, the plugin function call needs to be placed right after endwhile; and before $wp_query = null, like so:

<?php
  $temp = $wp_query;
  $wp_query= null;
  $wp_query = new WP_Query('cat=-6&paged=' . $paged);
  while ($wp_query->have_posts()) : $wp_query->the_post();
?>
 
<?php // the usual post-displaying codes here ?>
 
<?php
  endwhile;
  if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
  $wp_query = null; $wp_query = $temp; ?>

Placing the plugin call there will result in the correct pagination. You’ll get funky paging errors if it’s placed after the whole $wp_query variable swapping in the end.

How to Preview Child Themes using the Theme Preview Plugin

I mentioned in my How to Launch Your WordPress Theme guide that you can use a plugin to let visitor previews a theme applied to your current site (so you don’t have to build your own demo theme). For the current version of wplover I’m using the Theme Preview plugin by Dougal Campbell.

The example from that plugin’s installation guide is pretty simple, you just create a link like this:
http://example.com/index.php?preview_theme=my-theme

If you use custom permalinks (I suppose everyone does it at this point, you remove the “index.php” part:
http://example.com/preview_theme=my-theme

Then, your visitors can use that link to preview that my-theme you have. Now, things get interesting when you want to demo a child theme. This doesn’t get documented clearly, but you can do this to preview child themes:
http://example.com/preview_theme=parent-theme&preview_css=child-theme

It’s that simple. Remember to use the correct names for both the parent and child theme. If you’re not sure, just use the theme’s folder name. Here’s an example for A Simple Love‘s demo:

http://wplover.com/preview_theme=thematic&preview_css=a-simple-love

Also remember that you need both the parent and child theme in your wp-content/themes/ directory for this to work.

Hackers Highlight 3 May 2009

Welcome to the weekly Hackers Highlight, showcasing various interesting information that happened in the last week of WordPress hacker’s mailing list, wp-hackers. You can also follow the mailing list via the Google Group front-end here.

This could be an idea if you wanted to make a new plugin: Eduardo Zulian needed a way to show a huge amount of categories in the write post admin area. Could be really useful for sites using WP as a CMS with a lot of different categories in play.

Here’s a good discussion on WordPress’ accessibility issue. And related with that discussion, Lynne Pope requested the creation of the wp-accessibility mailing list to further discuss and implement better accessibility into WordPress. Quite obviously a great idea. Let’s hope this comes into reality real soon.

Hackers Highlight 26 April 2009

Welcome to the weekly Hackers Highlight, showcasing various interesting information that happened in the last week of WordPress hacker’s mailing list, wp-hackers. You can also follow the mailing list via the Google Group front-end here.

So there was a post on the WP dev blog asking folks for ideas and tweaks to the Dashboard design.  Jane Wells linked to the related WordPress forum thread if you want to contribute or just follow the discussion. The 2.8 navigation design guidelines are available here.

Mike Walsh asked for plugins that can handle forms to be included with sign-up activity. TDO Mini Forms and MM Forms were recommended. A bunch of non-WordPress solutions were also suggested.

Here’s Ptah Dunbar with a code snippet on how to automatically activate certain widgets.

There’s also an on-going discussion started by Michael Toppa on how to make a plugin that loads certain CSS only on pages that use that plugin. No definitive solution so far. Any takers?

Hackers Highlight 19 April 2009

Welcome to the weekly Hackers Highlight, showcasing various interesting information that happened in the last week of WordPress hacker’s mailing list, wp-hackers. You can also follow the mailing list via the Google Group front-end here.

Did you know the WordPress 24-Hours Has-Patch Marathon a few days before? Here’s a little inside story of what happened in wp-hackers. Some wanted to help but couldn’t because there’s no news posted at the mailing list, and the two days prior announcement post at the WP development blog were simply too short.

Stephen Rider suggested that it is better to revert from using the word “Appearance” back to “Design” inside the Dashboard. The change to “Appearance” happened within the 2.7 redesign, which changed all the menus from verbs to nouns. “Design” is also a noun, he said, and it encompassed the content underneath that menu better: Widgets, for example, are not just appearances but also part of the design of the site. Demetris suggested using the word “Layout” instead. What do you think?

Here’s a discussion on using the WP_Query() to display posts with a certain search term.

Hackers Highlight 12 April 2009

Wow, last weekend was quite a hectic one for me, and so this particular article goes out of schedule a bit. Anyways, as usually, this is the weekly Hackers Highlight, showcasing various interesting information that happened in the last week of WordPress hacker’s mailing list, wp-hackers.

First, I found out that the Google Groups frontend version of wp-hackers is a much pleasant version to read and link to, so I’m going to use that from now on.

Liraz Siri was working on including WordPress inside TurnKey Linux and then asked what plugins needs to be included with it. And so a bunch of WP hackers recommend their own list of good plugins to have when starting a new WP blog.

Shane A. Froebel released the wireframe document for the new Media Management System for WordPress 2.9.x. Sounds great. It’s on his blog, and also available as a PDF file (direct link, this one).

Here’s a nice and short discussion on best practices for using wp_enqueue_script and wp_enqueue_style, started by Michael Toppa.

Joost de Valk asked about some information on the syntax of WXR. Surprisingly, there is no such definitive resource anywhere!

Hackers Highlight 05 April 2009

This is the weekly Hackers Highlight, showcasing various interesting information that happened in the last week of WordPress hacker’s mailing list, wp-hackers.

 

Chris Jean questioned whether it’s possible to hide the parent of a child theme in the Manage Themes dashboard area. While this is potentially useful to avoid user confusion (so that they don’t activate the parent theme when they should be activating the child one), I don’t think this is a particularly necessary issue. Users might not even understand what a parent/child theme is: just tell them precisely what theme to activate, and that’s it.

Joost de Valk offered a small fix so that /wp-includes/link-template.php uses less database query. Nice catch.

Ptah Dunbar asked whether there’s a WordPress UI guidelines somewhere. Apparently there is one, except that it’s written in German. Anyone interested to do an English version?

Mike Schinkel found out that WordPress always run a query for posts regardless of whether you need it or not (say, if you’re using a custom query). The discussion that follows talked about ways to disable the query_posts() function.

Page 9 of 12« First...7891011...Last »

Latest Links More →

The Week in WordPress: 2nd Week of November, 2012

Ghost, Rethinking WordPress. Also don’t miss the discussion over at Hacker News.

For The Aspiring Professional WordPress Developer is a collection of good advices for those wanting to be a WordPress pro.

Recently I had the task of cloning a WordPress site both to my local server and to another development server that I host. The Duplicator plugin has been a massive help for me, makes cloning really simple and fast. Highly recommended.

Classy Plugins

Eric Mann uses classes in his non object-oriented WordPress code. Here’s why.

Playing Nice with the “the_content” Filter

This great article could be useful if for some reason you have a need to filter the_content in your theme.

Google Goes After Links In WordPress Themes

New post from the Search Engine Roundtable: Someone “…received a response from Google to a reconsideration request that the only way his site will be reincluded in Google is if he removes all or most of the links in those WordPress themes.” The problem is that those links are in the form of sponsored links on footer (a practice I saw a lot in the past, not so much in the present).

I don’t think it will be easy, or even possible, to do what Google requested. If a theme contains an upgrade notification feature it might be possible to do, but even then the users might choose not to upgrade.

Secondly, if this is true, I wonder whether Google differentiates between credit links (“Designed by…”) and sponsored links. I would say they should, but then again I’m not a SEO guy.

Theme Options Gallery

New favorite blog: Theme Options Gallery by Konstantin Kovshenin, discussing “the best (and the worst) theme options screens around”. Loving the in-depth article and discussions already available there.

Dive into Responsive Prototyping with Foundation

Pretty safe to say that if it shows up on A List Apart, it’s going to be the de facto standard. Time to learn some Foundation.

Google HTML/CSS Style Guide

Couple of days ago we got Starbucks’ style guide, and now here’s another by Google. I think the interesting thing is the rule to “\[o\]mit the protocol from embedded resources“. So instead of typing <script src="http://www.google.com/js/gweb/analytics/autotrack.js"></script>, they recommend to type <script src="//www.google.com/js/gweb/analytics/autotrack.js"></script> instead (without the http part). Never heard of that before.

“I Woke Up but My Server Wasn’t There”

Robb Shecter’s WordPress site got popular overnight thanks to Reddit and went down immediately. The interesting aspect is that the site was new and it’s on a relatively high-powered server. The author then found that the theme he used in particular was doing too many (47!) server requests at a time, and the site ran along very well after switching back to Twenty Eleven.

I think it’s an important read for any theme developers out there.

Read the story here

Modern Web Development – Part I: The Webkit Inspector

A superbly detailed article, part one of a series about web development toolchain.

Crayon Syntax Highlighter plugin

I’ve always been on the hunt for that perfect syntax highlighter plugin. Currently I’m using WP-Syntax, which does its job very well. However I’ve just found this plugin called Crayon Syntax Highlighter, which could be a good contender for the best WordPress syntax highlighter plugin out there.

It looks good, and I like the little toolbar on top of the code box, with the small icons. Additionally, it also offers a lot of customization options. Lastly, it seems to support the same pre tags to wrap the code, similar WP-Syntax, so if I do make the switch, my old codes will still be highlighted correctly.

Starbucks Style Guide

The Starbuck website has its own style guide, accessible for public. I think its a neat idea, wouldn’t it be cool if themes have their own style guide? Pretty sure it will be helpful both to users or developers alike, if time consuming to write.

Also, I wonder what they use for the various toggles panel on the top right corner like on this page. It shows background, baseline, boxes, can be used to change windows size as well. Looks like it’s custom coded, imagine how super useful it can be if it’s a jQuery plugin.

NHP Theme Options Framework

I love theme options frameworks. And I want you guys to check this new framework called NHP. It passes my “does its UI look like the rest of WordPress enough?” test (screenshots here), it has tons of field types, and even offer validations, too.

Can’t wait to test and probably use it too in my to-be-released theme hint hint

What Dev4Press thinks WordPress needs…

This post at Dev4Press outlines what MillaN, its author, thinks would be a necessary addition to WordPress.

Based on the comments, it appears that a lot of people agree with this list. Some of the items mentioned can be achieved with plugins (e.g Tax Meta Class to add meta data to taxonomy items, Custom Post Types Relationships for, well, creating custom post type relationships), so expect there to be a bunch of debates about what should and shouldn’t go to the core.

I like his list, but I disagree with his assessment that we don’t need new core themes. We do, especially to bring about the standard for how a theme options should be designed. This is the aspect that desperately needs to be standardized. Different theme companies and individual theme designers have their own idea of how the theme option UI should look, and it’s hurting the users.

Upgrading from WordPress 1.5

I recently spotted this interesting Ask Metafilter thread where user gd779 tries to find a way to upgrade his old, WordPress 1.5 install. One of the answer is pretty detailed:

I think the right approach is going to be:

  1. Do a full backup of your WordPress files
  2. Do a full database backup (mysql dump using phpMyAdmin or similar)

Then, from your 1.5.2 install:

  1. Upgrade to 2.0
  2. Upgrade to 2.5.1
  3. Upgrade to 3.0
  4. Upgrade to 3.3.1

It is quite fascinating thinking about the solution to this. There’s an official Codex page called Updating WordPress, but it doesn’t seem to go that far back in time.

Smashing Special: What’s Going On In The WordPress Economy?

Siobhan McKeown wrote this awesome, birds-eye view of the whole WordPress economy. Make sure to read this two-part article so you know what’s up with WordPress and identify what opportunity lies ahead.

I agree with Matt’s prediction on that article:

I think the next big opportunity is around agencies and consulting—there will be five to six companies as large as Automattic, just providing high-end consulting and services to the large customers who are adopting WordPress en masse.

Start with Part I of the article.

Automatic responsive images for WordPress

The one issue with creating responsive web design is in displaying images, especially getting the most appropriate size in a particular screen size. One solution for it is the Responsive-Enhance jQuery plugin. It works by loading small-sized images by default, then checks the screen size and loads the bigger version if necessary.

According to its creator, Josh Emerson:

This results in a faster perceived page load speed, but a slower actual speed. I’m happy with this solution as I care more about perceived speed than actual speed.

This tutorial by Keir Whitaker takes the whole thing further by teaching us how to apply Responsive-Enhance in WordPress.

css.php