Last active
December 14, 2015 06:39
-
-
Save rustyeddy/5044201 to your computer and use it in GitHub Desktop.
This function will display all children of a page along with the thumbnail. I have it setup with div class that will print them in a 2 wide grid. It calls the medium size. A couple of these things should be paramatized (is that a word?). :)
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
function lpo_display_child_pages_with_thumbs() | |
{ | |
global $wpdb; | |
global $post; | |
/* | |
* create a query that will locate all children of THIS page keeping | |
* the ORDER in specified in this page. | |
*/ | |
$sql = "SELECT * FROM $wpdb->posts WHERE post_parent = " . | |
$post->ID . " AND post_type = 'page' ORDER BY menu_order"; | |
// do the query | |
$child_pages = $wpdb->get_results( $sql, 'OBJECT' ); | |
$html = "<hr />"; | |
// walk the pages we have found | |
if ( $child_pages ) { | |
/* | |
* The $first variable is used to select the div elements that start | |
* a new row, this is strictly for styling (.css) purposes. | |
* | |
* this is all within the context of the 'columns' .css selectors provided | |
* by StudioPress. You can roll your own, it's simple. Ask me if you like. | |
*/ | |
$first = true; | |
/* | |
* every child page we have we are going to create a grid element (is that | |
* the right word?) | |
*/ | |
foreach ( $child_pages as $cp ) { | |
setup_postdata( $cp ); | |
// Get a 'medium' size featured image | |
$th = get_the_post_thumbnail( $cp->ID, 'medium' ); | |
$permalink = get_permalink( $cp->ID ); | |
/* | |
* This is where we create an alternating selector by turning the | |
* 'first' class on and off to create a two column grid. | |
*/ | |
$class = 'guide-directory-grid one-half'; | |
if ( $first ) { | |
$class .= ' first'; | |
} | |
// set the column selector | |
$html .= "<div class='" . $class . "'>\n"; | |
// Link the thumbnail image to the child page. | |
$html .= | |
"<a href='" . $permalink . "' rel='bookmark' title='" . $cp->post_title . "'>" . | |
$th . | |
"</a><br/>\n"; | |
// Might as well link the page title to the page as well. | |
$html .= "<p class='guide-title'>" . | |
"<a href='" . $permalink . "' rel='bookmark' title='" . $cp->post_title . "'>" . | |
$cp->post_title . | |
"</a><br/>\n"; | |
$html .= "<hr/></div>\n"; | |
// Toggle between being first and not first | |
$first = ! $first; | |
} | |
} | |
// spit it out | |
echo $html . "<br class='clear' />"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment