Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 17th, 2012  |  syntax: None  |  size: 3.77 KB  |  hits: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  50.  
  51. <div class="entry-content">
  52. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
  53. <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyeleven' ), 'after' => '</div>' ) ); ?>
  54. </div><!-- .entry-content -->
  55.  
  56. <div class="entry-utility">
  57. <?php if ( count( get_the_category() ) ) : ?>
  58. <span class="cat-links">
  59. <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyeleven' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
  60. </span>
  61. <span class="meta-sep">|</span>
  62. <?php endif; ?>
  63. <?php
  64. $tags_list = get_the_tag_list( '', ', ' );
  65. if ( $tags_list ):
  66. ?>
  67. <span class="tag-links">
  68. <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyeleven' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
  69. </span>
  70. <span class="meta-sep">|</span>
  71. <?php endif; ?>
  72. <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyeleven' ), __( '1 Comment', 'twentyeleven' ), __( '% Comments', 'twentyeleven' ) ); ?></span>
  73. <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  74. </div><!-- .entry-utility -->
  75. </div><!-- #post-## -->
  76.  
  77. <?php endforeach;
  78. // Move onto the next post in the category array
  79.  
  80. // We've finished!
  81. endforeach;
  82.  
  83. // We now need to check that we did manage to display at least 1 post
  84. if ( $posts_count == 0 ) :
  85. // Uh oh - we didn't display any posts! ?>
  86. <div id="post-0" class="post error404 not-found">
  87. <h1 class="entry-title"><?php _e( 'Not Found', 'twentyeleven' ); ?></h1>
  88. <div class="entry-content">
  89. <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
  90. <?php get_search_form(); ?>
  91. </div><!-- .entry-content -->
  92. </div><!-- #post-0 -->
  93. <?php endif;?>
  94.  
  95. </div><!-- #content -->
  96. </div><!-- #primary -->
  97.  
  98. <?php get_sidebar(); ?>
  99. <?php get_footer();