-
-
Save mac4media/c5bcfba1b20391b983f2 to your computer and use it in GitHub Desktop.
Add Post Info to Grid
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 | |
/* | |
Template Name: Filterable Categories | |
*/ | |
add_filter( 'body_class', 'ix_body_class' ); | |
/** | |
* Adds a css class to the body element | |
* | |
* @param array $classes the current body classes | |
* @return array $classes modified classes | |
*/ | |
function ix_body_class( $classes ) { | |
$classes[] = 'filterable-categories-page'; | |
return $classes; | |
} | |
add_filter( 'genesis_attr_site-inner', 'ix_attributes_site_inner' ); | |
/** | |
* Add attributes for site-inner element. | |
* | |
* @since 2.0.0 | |
* | |
* @param array $attributes Existing attributes. | |
* | |
* @return array Amended attributes. | |
*/ | |
function ix_attributes_site_inner( $attributes ) { | |
$attributes['role'] = 'main'; | |
$attributes['itemprop'] = 'mainContentOfPage'; | |
return $attributes; | |
} | |
// Remove div.site-inner's div.wrap | |
add_filter( 'genesis_structural_wrap-site-inner', '__return_empty_string' ); | |
// Display Header | |
get_header(); | |
wp_enqueue_script( 'mixitup', get_stylesheet_directory_uri() . '/lib/js/jquery.mixitup.min.js', array( 'jquery' ), '2.1.11', true ); | |
wp_enqueue_script( 'mixitup-init', get_stylesheet_directory_uri() . '/lib/js/mixitup-init.js', array( 'mixitup' ), '1.0.0', true ); | |
// Content | |
the_post(); // sets the 'in the loop' property to true. | |
the_content(); | |
$args = array( | |
'orderby' => 'name', | |
'parent' => '0', // get the top level categories only | |
'hierarchical' => 0, // do not include sub-categories that are empty, as long as those sub-categories have sub-categories that are not empty. | |
); | |
$categories = get_categories( $args ); ?> | |
<!-- Categories Filter --> | |
<div id="category-names-filter" class="clearfix"> | |
<button class="filter" data-filter="all"><?php _e('All', 'genesis'); ?></button> | |
<?php foreach ( $categories as $category ) : ?> | |
<button class="filter" data-filter=".category-<?php echo $category->slug; ?>"><?php echo $category->name; ?></button> | |
<?php endforeach; ?> | |
</div> | |
<div id="posts-list"> | |
<?php $cat_ids = array(); | |
foreach ( $categories as $category ) { | |
$cat_ids[] .= $category->cat_ID; | |
} | |
// WP_Query arguments | |
$cat_args = (array( | |
'category__in' => $cat_ids, | |
'posts_per_page' => -1 | |
)); | |
// The Query | |
$query = new WP_Query( $cat_args ); | |
// The Loop | |
if ( $query->have_posts() ) { | |
while ( $query->have_posts() ) { | |
$query->the_post(); | |
// do something ?> | |
<article <?php post_class(); ?>> | |
<?php // image | |
if ( has_post_thumbnail() ) { | |
$image = genesis_get_image( array( 'format' => 'url', 'size' => 'masonry-brick-image' ) ); | |
} else { | |
$image = get_stylesheet_directory_uri() . '/images/default-image.png'; | |
} | |
printf( '<a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); ?> | |
<!-- title --> | |
<h2 class="entry-title" itemprop="headline"><a href="<?php the_permalink(); ?>" rel="bookmark" title="Go to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> | |
<div><?php echo do_shortcode( '[post_categories before=""]') ?></div> | |
<div class="wprs_archive_rating_stars"><?php echo do_shortcode('[wprs-rating]') ?></div> | |
</article> | |
<?php } | |
} else { | |
// no posts found | |
} | |
// Restore original Post Data | |
wp_reset_postdata(); ?> | |
<!-- inline-block "gap" elements for an even grid --> | |
<div class="gap"></div> | |
<div class="gap"></div> | |
</div> | |
<?php // Display Footer | |
get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to add post meta below the title (line 105) not working