Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- get_header(); ?>
- <div id="primary">
- <div id="content" role="main">
- <?php
- /* Set up an array to hold the ids for the categories we want to pull from
- * The order in which the posts are called & displayed is goverened by their
- * placement in this array
- */
- $my_cat_array = array(5,3,22,1);
- /*
- * Set up a flag that will indicate if we've returned ANY posts from any of the chosen categories
- * As we don't have access to the standard Loop 404, we'll need this in case we
- * bomb out on all categories. This kind of post counter can come in useful elsewhere...
- */
- $posts_count = 0;
- /*
- * Rather than modify the main Loop, we'll use get_posts to create 3 secondary loops that grab * the first post from each of these categories. This has the benefit of leaving the main Loop * untouched if you want to call it later on in the page.
- */
- foreach ( $my_cat_array as $my_cat) :
- // Set up the secondary loop query
- $args = array(
- 'numberposts' => 1, // number of posts to return
- 'cat' => $my_cat // the category id
- );
- $lastpost = get_posts($args);
- // If we have at least 1 post, increment the post_counts flag
- if( count( $lastpost ) > 0 ) $posts_count++;
- // We still have to run a foreach Loop - even if there's only 1 post.
- foreach($lastpost as $post) :
- /*
- * Call the internal function setup_postdata(), with the $post array as its argument
- * This is so that we can access all post data
- */
- setup_postdata($post);
- // Now we can display the post using all of the standard Loop tags
- ?>
- <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
- <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
- <?php if ( 'post' == get_post_type() ) : ?>
- <div class="entry-meta">
- <?php twentyeleven_posted_on(); ?>
- </div><!-- .entry-meta -->
- <?php endif; ?>
- <div class="entry-content">
- <?php the_content( __( 'More <span class="meta-nav">»</span>', 'twentyeleven' ) ); ?>
- <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyeleven' ), 'after' => '</div>' ) ); ?>
- </div><!-- .entry-content -->
- <div class="entry-utility">
- <?php if ( count( get_the_category() ) ) : ?>
- <span class="cat-links">
- <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyeleven' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
- </span>
- <span class="meta-sep">|</span>
- <?php endif; ?>
- <?php
- $tags_list = get_the_tag_list( '', ', ' );
- if ( $tags_list ):
- ?>
- <span class="tag-links">
- <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyeleven' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
- </span>
- <span class="meta-sep">|</span>
- <?php endif; ?>
- <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyeleven' ), __( '1 Comment', 'twentyeleven' ), __( '% Comments', 'twentyeleven' ) ); ?></span>
- <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
- </div><!-- .entry-utility -->
- </div><!-- #post-## -->
- <?php endforeach;
- // Move onto the next post in the category array
- // We've finished!
- endforeach;
- // We now need to check that we did manage to display at least 1 post
- if ( $posts_count == 1 ) :
- // Uh oh - we didn't display any posts! ?>
- <div id="post-0" class="post error404 not-found">
- <h1 class="entry-title"><?php _e( 'Not Found', 'twentyeleven' ); ?></h1>
- <div class="entry-content">
- <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
- <?php get_search_form(); ?>
- </div><!-- .entry-content -->
- </div><!-- #post-0 -->
- <?php endif;?>
- </div><!-- #content -->
- </div><!-- #primary -->
- <?php get_sidebar(); ?>
- <?php get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement