Advertisement
Guest User

Untitled

a guest
May 8th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. <?php
  2.  
  3. get_header(); ?>
  4.  
  5. <div id="primary">
  6. <div id="content" role="main">
  7.  
  8. <?php
  9. /* Set up an array to hold the ids for the categories we want to pull from
  10. * The order in which the posts are called & displayed is goverened by their
  11. * placement in this array
  12. */
  13. $my_cat_array = array(5,3,22,1);
  14.  
  15. /*
  16. * Set up a flag that will indicate if we've returned ANY posts from any of the chosen categories
  17. * As we don't have access to the standard Loop 404, we'll need this in case we
  18. * bomb out on all categories. This kind of post counter can come in useful elsewhere...
  19. */
  20. $posts_count = 0;
  21.  
  22. /*
  23. * 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.
  24. */
  25. foreach ( $my_cat_array as $my_cat) :
  26.  
  27. // Set up the secondary loop query
  28. $args = array(
  29. 'numberposts' => 1, // number of posts to return
  30. 'cat' => $my_cat // the category id
  31. );
  32. $lastpost = get_posts($args);
  33.  
  34. // If we have at least 1 post, increment the post_counts flag
  35. if( count( $lastpost ) > 0 ) $posts_count++;
  36.  
  37. // We still have to run a foreach Loop - even if there's only 1 post.
  38. foreach($lastpost as $post) :
  39.  
  40. /*
  41. * Call the internal function setup_postdata(), with the $post array as its argument
  42. * This is so that we can access all post data
  43. */
  44. setup_postdata($post);
  45.  
  46. // Now we can display the post using all of the standard Loop tags
  47. ?>
  48. <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  49. <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>
  50.  
  51. <?php if ( 'post' == get_post_type() ) : ?>
  52. <div class="entry-meta">
  53. <?php twentyeleven_posted_on(); ?>
  54. </div><!-- .entry-meta -->
  55. <?php endif; ?>
  56.  
  57. <div class="entry-content">
  58. <?php the_content( __( 'More <span class="meta-nav">&raquo;</span>', 'twentyeleven' ) ); ?>
  59. <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyeleven' ), 'after' => '</div>' ) ); ?>
  60. </div><!-- .entry-content -->
  61.  
  62. <div class="entry-utility">
  63. <?php if ( count( get_the_category() ) ) : ?>
  64. <span class="cat-links">
  65. <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyeleven' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
  66. </span>
  67. <span class="meta-sep">|</span>
  68. <?php endif; ?>
  69. <?php
  70. $tags_list = get_the_tag_list( '', ', ' );
  71. if ( $tags_list ):
  72. ?>
  73. <span class="tag-links">
  74. <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyeleven' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
  75. </span>
  76. <span class="meta-sep">|</span>
  77. <?php endif; ?>
  78. <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyeleven' ), __( '1 Comment', 'twentyeleven' ), __( '% Comments', 'twentyeleven' ) ); ?></span>
  79. <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  80. </div><!-- .entry-utility -->
  81. </div><!-- #post-## -->
  82.  
  83. <?php endforeach;
  84. // Move onto the next post in the category array
  85.  
  86. // We've finished!
  87. endforeach;
  88.  
  89. // We now need to check that we did manage to display at least 1 post
  90. if ( $posts_count == 1 ) :
  91. // Uh oh - we didn't display any posts! ?>
  92. <div id="post-0" class="post error404 not-found">
  93. <h1 class="entry-title"><?php _e( 'Not Found', 'twentyeleven' ); ?></h1>
  94. <div class="entry-content">
  95. <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
  96. <?php get_search_form(); ?>
  97. </div><!-- .entry-content -->
  98. </div><!-- #post-0 -->
  99. <?php endif;?>
  100.  
  101. </div><!-- #content -->
  102. </div><!-- #primary -->
  103.  
  104. <?php get_sidebar(); ?>
  105. <?php get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement