WordPress Portal

This is a library/plugin to ease complex themes development in WordPress. Its main feature is the custom The Loop creator, useful to manage complex and information-dense layouts, but it gives also many other functions to shortcut some common tasks.

Its dual interface - library/plugin - is designed to allow easy upgrading.

Currently supports WordPress 2.3+.
Use WPP version 0.5 for WordPress 2.1/2.2.

Usage

These are the functions usable once WPP has been included or plugged:

wpp::foreach_post($filter, $limit = null)
Creates a custom The Loop. Its first parameter could be either a raw string defining an SQL WHERE clause or an array where each key=>value pair becomes a string of key = 'value', joined with AND.
The good thing is that you can pass also: a page nicename (slug) or a category nicename (slug) and it will get all the matching content.
The filter parameter is just the LIMIT part of the query: write '3' and you'll get three posts, write '3,10' and you'll get ten posts starting from third.
wpp::get_posts($filter, $limit = null)
Same parameters as wpp::foreach_post(), but returns an array instead of creating a custom The Loop
wpp::get_terms_recursive($ref, $levels = -1, $taxonomy = 'category')
Gets all the Term rows from the database, starting from the one matching the nicename (slug) passed as $ref and adding all its children.
The returned array is flat, not hierarchical.
The $levels parameters specify how deep it should recurse, by default it's unlimited.
wpp::in_category($nicename)
Usable only inside The Loop or The Loop custom.
It checks if the current post belongs to the category passed as nicename (slug).
wpp::is_term_child_of($child_term, $parent_term)
Checks if the $child_term is the same or a child of $parent_term.
wpp::get_post_custom($custom, $before = '', $after = '', $optid = 0)
Usable only inside The Loop or The Loop custom (without $optid).
Returns a specific post custom field.
It could wrap the results (using $before and $after) and could refer to a specific post (identified by the ID) using $optid.
wpp::get_page_content($nicename, $on_empty = "The page '%s' is empty.")
Gets a string with the content of the page identified by the nicename (slug).
It returns a customizable message if it's not found.
wpp::get_zone($key = null)
Returns an array containing zone type, zone id and if possible the matching Terms array.
array('type' => ..., 'id' => ..., 'terms' => array(...)).
The WP zone types are matching the is_* functions (i.e. is_page, is_single, ...), while the id is the unique identifier for that zone type (i.e. for pages and post, the post id; for categories the category nicename, ...).
The returned types are: page, post, author, search, category, date, tag, home.
wpp::is_admin($uid = 0)
Check if the current user is an Administrator.
Pass an user ID to check a specific user.
wpp::get_last_comments($size = 10, $id = 0)
Gets an array with the last 10 comments (use $size to specify how many).
Pass a post ID to retrieve the last $size posts from a specific post.
wpp::get_last_comments_grouped($size = 10)
Gets an array with the last 10 commented posts, each one with the last comment details.
wpp::get_pages_root()
Retrieves the top page in the current hierarchy of pages.
The hierarchy of pages starts with a root top page and goes down its children.
wpp::list_pages_of_section($arguments = '&title_li=')
Like wp_list_pages(), but it returns just the current hierarchy of pages.
This function is related to wpp::get_pages_root().

Examples

Custom The Loop, by Page, passing just its nicename (slug) and then using it inside the block with any The Loop function.

while (wpp::foreach_post(array('page' => 'about'))) {
	echo the_content();
}
		

Custom The Loop, by Category, choosing all the posts from the 'blue' category (and all its sub-categories) and limiting to the top 5 entries sorted automatically by date.
Note the function wpp::in_category that is checking a different category: if 'azure' is a sub-category of 'blue', it will show also the custom field named 'color'.

while (wpp::foreach_post(array('category' => 'blue'), 5)) {
	echo the_title();
	if (wpp::in_category('azure')) {
		echo wpp::get_post_custom('color');
	}
}
		

Get Posts, choosing all the posts from the 'corporate' category (and all its sub-categories) and limiting to the top 2 entries sorted automatically by date.

$posts = wpp::get_posts(array('category' => 'corporate'), 2);
echo $posts[0]->post_content;
echo $posts[1]->post_content;
		

Download

NOTE: this class is designed to be included WITH the template. But, in order to support separated updates, it could be also added as a plugin: the newer version will be used instead of the template one.

Changelog

0.7.1 (2008 05 15)
Improved foreach_post() support for The Loop structures using setup_postdata() WP internal function to handle initialization.
0.7 (2007 10 03)
Fixed in-file documentation errors.
0.7 (2007 09 29)
Changed WPP interface to static 'wpp' class. Usage as before, but statically called.
0.6 (2007 09 27)
Upgraded the library to WordPress 2.3, with a few improvements.
0.5 (2007 08 03)
First public release