Advertisement
Guest User

Untitled

a guest
Oct 20th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Template Name: Whatever
  4. */
  5.  
  6. // First we need to dump out the contents of the page itself,
  7. // that's where the standard loop comes into play
  8. // e.g. If the page has content, (yes/no), while the page has content (if yes then),
  9. // the_post (loop through to display our page's content).
  10.  
  11. if ( have_posts() ) : while ( have_posts() ) : the_post();
  12.     // The page's title
  13.     ?>
  14.     <h2><?php the_title(); ?></h2>
  15.    
  16.     <?php
  17.     // The page itself's content
  18.     the_content();
  19.    
  20.     // End the loop
  21.     endwhile;
  22. // End the if statement
  23. endif;
  24.  
  25. // Let's query for and display some posts now
  26.  
  27. // Setup our query arguments
  28. // Reference: http://codex.wordpress.org/Class_Reference/WP_Query
  29.  
  30. $args = array(
  31.     // Number of posts
  32.     'posts_per_page' => 5,
  33.     // Specific category
  34.     'category_name' => 'something'
  35. );
  36.  
  37. // Now set a variable to hold your posts loop
  38. // Call it whatever you like
  39. $loop = new WP_Query( $args );
  40.  
  41. // Run our posts Loop, start with checking if anything was found
  42. if ( $loop->have_posts() ) :
  43.     // Loop through results if some found
  44.     while ( $loop->have_posts() ) : $loop->the_post();
  45.     ?>
  46.     <h3><?php the_title(); ?></h3>
  47.     <?php // Show the post's excerpt
  48.     the_excerpt();
  49.    
  50.     // End our posts loop
  51.     endwhile;
  52. // End our if statement
  53. endif;
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement