Skip to content

Instantly share code, notes, and snippets.

@jdspiral
Last active May 22, 2017 23:16
Show Gist options
  • Save jdspiral/9fef0063193ac76c4c25 to your computer and use it in GitHub Desktop.
Save jdspiral/9fef0063193ac76c4c25 to your computer and use it in GitHub Desktop.
Custom Genesis Loop
remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'jds_do_loop');
function jds_do_loop() {
$args = array(
'posts_per_page' => 20,
'post_type' => 'page',
'post_parent' => 5,
'paged' => get_query_var( 'paged' ),
'orderby' => 'title',
'order' => 'ASC',
);
global $wp_query;
$wp_query = new WP_Query( $args );
if( $wp_query->have_posts() ): // If there the query has posts
while( $wp_query->have_posts() ): $wp_query->the_post(); // while there are posts, get and output the posts
global $post;
$default_attr = array(
'class' => "alignleft post-image entry-image",
'itemprop' => "image",
'title' => get_the_title()
//'alt' => trim( strip_tags( $wp_query->post_excerpt ) ),
//'title' => trim( strip_tags( $wp_query->post_title ) ),
);
echo '<article class="post type-post status-publish format-standard entry" itemscope="itemscope" itemtype="http://schema.org/BlogPosting" style="clear:both;margin-bottom: 20px;border-bottom: 1px #CCC solid;">
<header class="entry-header">
<h1 class="entry-title" itemprop="headline">
<a href="' . get_permalink() . '">' . get_the_title() .'</a>
</h1>
</header>
<div class="entry-content" itemprop="text">
<a href="' . get_permalink() . '">' . get_the_post_thumbnail( $post->ID, 'thumbnail', $default_attr ) . '</a><p>' . get_the_excerpt() . '</p>
</div>
</article>';
endwhile;
genesis_posts_nav();
endif;
wp_reset_query();
}
add_filter( 'excerpt_length', 'jds_excerpt_length' );
function jds_excerpt_length( $length ) {
return 52; // pull first 50 words
}
// Replaces the excerpt "more" text by a link
function jds_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '">...Read More.</a>';
}
add_filter('excerpt_more', 'jds_excerpt_more');
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment