Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // First, let's eliminate some DRY,
- // by making an array of our categories
- $random_posts_cat_array = array( 'artists', 'projects', 'people', 'development', 'offsite', 'contact' );
- // Globalize $post,
- // since we're outside the primary loop
- global $post;
- $post_cat = get_the_category( $post->ID );
- // Current post category ID
- $post_cat_id = $post_cat->cat_ID;
- // Current post category slug
- $post_cat_slug = $post_cat->slug;
- // Now, let's find out if we're displaying
- // the category index for one of our categories
- if ( in_array( $random_posts_cat_array, $post_cat_slug ) ) {
- // Set up custom loop args
- $random_posts_query_args = array(
- 'post_per_page' => 3,
- 'orderby' => 'rand'
- );
- // Add Cat ID to custom loop args
- foreach ( $random_posts_cat_array as $random_post_cat ) {
- if ( $post_cat_slug == $random_post_cat ) {
- // Add Cat ID
- $random_posts_query_args['cat'] = $post_cat_id;
- }
- // Run random posts query
- $random_posts_query = new WP_Query( $random_posts_query_args );
- // Setup random posts query loop
- if ( $random_posts_query->have_posts() ) : while ( $random_posts_query->have_posts() ) : $random_posts_query->the_post();>?>
- <h2>Plop sticks</h2>
- <?php foreach( get_the_category() as $cat ) echo '<div class="module ' . $cat->slug . '" data-category="' . $cat->slug . '" >'; ?>
- <a href="<?php the_permalink()?>" title="<?php the_title(); ?>">
- <div class="active">
- <div class="hover"></div>
- <?php the_post_thumbnail(); ?>
- </div>
- <?php
- $sub_title=get_post_meta($post->ID,'subtitle',true);
- if($sub_title != '') {
- echo '<h1>'. get_the_title() .'<span> / '. $sub_title .'</span></h1>';
- } else {
- echo '<h1>'. get_the_title() .'</h1>';
- }
- ?>
- <?php
- // Call in the contents of a custom field called Excerpt and if custom field in admin panel is empty don't display <p> tags otherwise wrap contents in <p> tags
- $excerpt=get_post_meta($post->ID,'Excerpt',true);
- if($excerpt != '') {
- echo '<p>'. $excerpt .'</p>';
- } else {
- echo ' ';
- }
- ?>
- <p class="date"><?php the_time('YdmHi') ?></p>
- </a>
- </div>
- <?php endwhile; endif;
- // Be kind; rewind
- wp_reset_postdata();
- } else { ?>
- <p>There is nothing to display</p>
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement