Created
February 4, 2011 08:06
-
-
Save alderete/810860 to your computer and use it in GitHub Desktop.
A starter template for the Custom Loop API in the Thesis theme for WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Source and explanation of this file: | |
// http://aldosoft.com/blog/2011/01/thesis-custom-loop-template/ | |
class my_looper extends thesis_custom_loop { | |
function home() { | |
thesis_loop::home(); | |
} | |
function front() { | |
thesis_loop::front(); | |
} | |
function single() { | |
thesis_loop::single(); | |
} | |
function attachment() { | |
thesis_loop::attachment(); | |
} | |
function page() { | |
thesis_loop::page(); | |
} | |
function archive() { | |
thesis_loop::archive(); | |
} | |
function category() { | |
thesis_loop::category(); | |
} | |
function tag() { | |
thesis_loop::tag(); | |
} | |
function tax() { | |
thesis_loop::tax(); | |
} | |
function author() { | |
thesis_loop::author(); | |
} | |
function year() { | |
thesis_loop::year(); | |
} | |
function month() { | |
thesis_loop::month(); | |
} | |
function day() { | |
thesis_loop::day(); | |
} | |
function search() { | |
thesis_loop::search(); | |
} | |
function fourohfour() { | |
thesis_loop::fourohfour(); | |
} | |
function nothing() { | |
thesis_loop::nothing(); | |
} | |
private function preserve_query_params($new_params = array()) { | |
global $wp_query; | |
return(array_merge($wp_query->query, $new_params)); | |
} | |
private function get_paged_param() { | |
if(is_front_page()) { | |
$paged = (get_query_var('page') ? get_query_var('page') : 1); | |
} | |
else { | |
$paged = (get_query_var('paged') ? get_query_var('paged') : 1); | |
} | |
return($paged); | |
} | |
} | |
$custom_looper = new my_looper; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* These are the different Thesis loops that can be customized. | |
* | |
* Replace the calls to the default Thesis loops with your own code. | |
* You can also delete any unused loop methods. | |
* | |
* @link http://codex.wordpress.org/Conditional_Tags More details of | |
* which page requests trigger which specific loops. | |
* @link http://aldosoft.com/blog/2011/01/the-thesis-custom-loop-api/ Detailed | |
* article about how to use the Custom Loop API. | |
*/ | |
class my_looper extends thesis_custom_loop { | |
/** | |
* The loop for the blog index page. | |
* | |
* By default this is the home or top-level index page. | |
* Can be changed to any page using Settings > Reading > Posts Page. | |
* | |
* This loop is used by the {@link archive()} loop (and all child loops) | |
* unless Thesis > Design Options > Display Options > Archives is | |
* set to Titles Only. | |
*/ | |
function home() { | |
thesis_loop::home(); | |
} | |
/** | |
* The loop for the front page of the site if configured in | |
* Settings > Reading > Front Page. | |
* | |
* Has no effect if no front page is set. | |
* | |
* By default, delegates to the {@link page()} loop. | |
*/ | |
function front() { | |
thesis_loop::front(); | |
} | |
/** | |
* The loop for displaying an individual post, i.e. the | |
* one-article-per-page view of a post. | |
* | |
* Sometimes referred to as "single-entry pages". | |
*/ | |
function single() { | |
thesis_loop::single(); | |
} | |
/** | |
* The loop for displaying an individual attachment on a post, | |
* usually an image. | |
* | |
* By default, delegates to the {@link single()} loop. | |
*/ | |
function attachment() { | |
thesis_loop::attachment(); | |
} | |
/** | |
* The loop for a static, individual page. | |
*/ | |
function page() { | |
thesis_loop::page(); | |
} | |
/** | |
* Default loop for archive-style pages. | |
* | |
* This loop is the default for category, tag, tax, author, | |
* day, month, year, and search pages. | |
* | |
* Important: Delegates to {@link home()} unless | |
* Thesis > Design Options > Display Options > Archives is | |
* set to Titles Only. | |
*/ | |
function archive() { | |
thesis_loop::archive(); | |
} | |
/** | |
* Loop for category pages. | |
* | |
* By default, delegates to the {@link archive()} loop. | |
*/ | |
function category() { | |
thesis_loop::category(); | |
} | |
/** | |
* Loop for tag pages. | |
* | |
* By default, delegates to the {@link archive()} loop. | |
*/ | |
function tag() { | |
thesis_loop::tag(); | |
} | |
/** | |
* Loop for custom taxonomy pages. | |
* | |
* Has no effect unless you have defined a custom taxonomy. | |
* | |
* By default, delegates to the {@link archive()} loop. | |
*/ | |
function tax() { | |
thesis_loop::tax(); | |
} | |
/** | |
* Loop for author pages. | |
* | |
* By default, delegates to the {@link archive()} loop. | |
*/ | |
function author() { | |
thesis_loop::author(); | |
} | |
/** | |
* Loop for year-level date archive pages. | |
* | |
* By default, delegates to the {@link archive()} loop. | |
*/ | |
function year() { | |
thesis_loop::year(); | |
} | |
/** | |
* Loop for month-level date archive pages. | |
* | |
* By default, delegates to the {@link archive()} loop. | |
*/ | |
function month() { | |
thesis_loop::month(); | |
} | |
/** | |
* Loop for day-level date archive pages. | |
* | |
* By default, delegates to the {@link archive()} loop. | |
*/ | |
function day() { | |
thesis_loop::day(); | |
} | |
/** | |
* Loop for search results page. | |
* | |
* By default, delegates to the {@link archive()} loop IF THERE ARE RESULTS. | |
* By default, just shows a search form if there are no results. | |
* | |
* A custom search loop needs to deal with both possibilities; see the | |
* {@link thesis_loop::search()} for example of how to do so. | |
*/ | |
function search() { | |
thesis_loop::search(); | |
} | |
/** | |
* Loop for the "404 Not Found" error page. | |
* | |
* Runs when the URL requested could not be mapped to any page. | |
*/ | |
function fourohfour() { | |
thesis_loop::fourohfour(); | |
} | |
/** | |
* Loop for page without any posts/pages (an empty query). | |
* | |
* Runs when the URL requested maps to a legitimate page, but there | |
* is no post data to display. Should be rare. | |
*/ | |
function nothing() { | |
thesis_loop::nothing(); | |
} | |
/* PRIVATE HELPER METHODS */ | |
/** | |
* Merge new query parameters with existing parameters. | |
* | |
* This preserves existing request parameters, for compatibility | |
* with plugins, etc. | |
* | |
* New parameters overwrite existing parameters with same name. | |
* | |
* @access private | |
* @param array $new_params Parameters for a new query via | |
* {@link query_posts()} or a new {@link WP_Query}. | |
* @global $wp_query is used to get the current request parameters. | |
* | |
* @return array The merged parameters array, ready for passing to | |
* {@link WP_Query::query_posts()} or | |
* {@link WP_Query::get_posts()}. | |
*/ | |
private function preserve_query_params($new_params = array()) { | |
global $wp_query; | |
return(array_merge($wp_query->query, $new_params)); | |
} | |
/** | |
* Retrieve the current "paged" parameter from the request. | |
* | |
* This is used for "paging" through the query results. | |
* See {@link http://aldosoft.com/blog/2011/01/thesis-custom-loop-template/ | |
* for details.} | |
* | |
* This method deals with a WordPress idiosyncracy / inconsistency in the | |
* name of this parameter. | |
* | |
* @access private | |
* @uses WP_Query::get_query_var() | |
* | |
* @return int The current paged parameter. | |
*/ | |
private function get_paged_param() { | |
if(is_front_page()) { | |
$paged = (get_query_var('page') ? get_query_var('page') : 1); | |
} | |
else { | |
$paged = (get_query_var('paged') ? get_query_var('paged') : 1); | |
} | |
return($paged); | |
} | |
} | |
$custom_looper = new my_looper; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment