Skip to content

Instantly share code, notes, and snippets.

@srikat

srikat/page.php Secret

Last active May 24, 2016
Embed
What would you like to do?
<?php
add_filter( 'body_class', 'sk_body_class_pages' );
/**
* Adds a css class to the body element
*
* @param array $classes the current body classes
* @return array $classes modified classes
*/
function sk_body_class_pages( $classes ) {
if ( ! $post->post_parent ) { // if this is a parent Page
$classes[] = 'sub-pages-grid';
}
return $classes;
}
// Display sub-Pages grid of the current Page (if it is a parent Page) after Page content
add_action( 'genesis_entry_content', 'sk_sub_pages' );
function sk_sub_pages() {
$args = array(
'parent' => get_the_id(), // no grandchildren
// 'sort_column' => 'menu_order', // sort by Page Order. Remove this to sort alphabetically
);
$pages = get_pages( $args );
if ( $pages ) { // if this is a Parent Page
$pageids = array();
// counter for adding "first" class to every third item in the loop
$i = 0;
echo '<div class="sub-pages">';
foreach ( $pages as $page ) {
setup_postdata( $page ); // to make template tag [excerpt() in this case] specific to loop
echo '<article class="sub-page one-third';
if ( ( $i % 3 ) == 0 ) { echo ' first">'; } else { echo '">'; }
// get featured image URL
$img = genesis_get_image( array(
'post_id' => $page->ID,
'format' => 'url',
'size' => 'sub-pages',
) );
// if the Page does not have a featured image, set a default placeholder image URL
if ( ! $img ) {
$img = 'http://placeholdit.imgix.net/~text?txtsize=64&txt=Default%20Image&w=800&h=389';
}
// store the value of 'custom_page_excerpt' custom field in a variable
$custom_page_excerpt = get_post_meta( $page->ID, 'custom_page_excerpt', true );
// output linked image
printf( '<a href="%s" rel="bookmark" class="sub-page-image"><img src="%s" alt="%s" itemprop="image"></a>', get_permalink( $page->ID ), $img, the_title_attribute( array( 'echo' => 0, 'post' => $page->ID ) ) );
// linked title
echo '<h3 class="subpage-title"><a href="' , get_permalink( $page->ID ) , '">' , get_the_title( $page->ID ) , '</a></h3>';
// excerpt
// echo '<div class="excerpt">' , excerpt( '20' ) , '</div>';
echo '<div class="excerpt">';
// if custom page excerpt has been entered for the Page, show it otherwise, the automatic excerpt
if ( $custom_page_excerpt ) {
echo $custom_page_excerpt;
} else {
echo excerpt( '20' );
}
echo '</div>';
// read more
echo '<a class="read-more button" href="' , get_permalink( $page->ID ) , '">More</a>';
echo '</article>';
$i++; // increment the counter
}
wp_reset_postdata(); // to reset setup_postdata()
echo '</div>';
}
if ( function_exists( 'genesis_share_icon_output' ) ) {
global $Genesis_Simple_Share;
genesis_share_icon_output( 'after-entry', $Genesis_Simple_Share->icons );
}
}
genesis();
.share-after-entry {
clear: both;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment