Monthly Archives: May 2010

Filters to Modify a Query

UPDATE: See the excellent variation by keesiemeijer here: https://gist.github.com/4643765

Many times it is necessary to use a filter to modify a query.  For example, you may want to include a column that WP does not normally include in a query.  Or, you may want to do some complex selection of posts based on criteria that query_posts does not supply.  Continue reading

First and Last Post on a Page

If you want to detect the first and last post on a page (not the entire query), you can use the code below:

if (have_posts()) : while (have_posts()) : the_post();
  $c++;
  if( $c == 1 ) {
    $style='first';
  } elseif ( $c == $wp_query->post_count ) ) {
    $style='last';?>
  }
  // Rest of the code for the Loop

Select meta_value between limits

This code was written for a user to select posts based on the value of a Custom Field between min and max limits. Continue reading

Pagination of Array / Custom Query


NOTE:

As of WP 3.3.1, I have had problems using this approach with pretty permalinks. Please use the paginate_links() technique instead.


The mam_paginate() function shown here can be used to paginate a Custom Query or any array. I use it instead of paginate_links() when I want more control over the output. It can also be used outside of WordPress with only slight modification. Continue reading

Child Theme

Child themes are a great way to customize a theme without the chance of losing your changes when the theme is updated. Here are some resources to explain how to use them:

http://codex.wordpress.org/Child_Themes

A tutorial

http://themeshaper.com/wordpress-child-theme-basics/

Hide/Display Widgets on Selected Pages

Here is a plugin to Hide or Display Widgets on selected pages: Hide/Display Widgets on Selected Pages

Here is a newer one that has been tested up to WP 3.1 Widget Logic

Using WP in an Existing Site

If you have an existing site, and you want all or part of it to look like your favorite WordPress theme, the Codex has some information about how to do that.

http://codex.wordpress.org/Integrating_Wordpress_with_Your_Website

Useful SQL Queries

Here are some articles with SQL queries that may be useful:

13 Useful SQL Queries NOTE: this site appears to make IE8 hang.

http://wpmu.org/8-tips-for-keeping-a-squeaky-clean-wordpress-database/

Posts from Custom Query

This Codex article has a detailed explanation of how to create a template using a Custom Query:

http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

Add [raw] shortcode to display code

NOTE: This code appears to fail in WP 3.0.  Use the SyntaxHighlighter Evolved plugin instead. Continue reading