Advertisement
srikat

Untitled

Feb 23rd, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. // Display 1 latest Post and 5 Featured Pages
  2. function sk_home_featured() {
  3.  
  4. // WP_Query arguments
  5. $args1 = array (
  6. 'post_type' => 'post',
  7. 'posts_per_page' => '1',
  8. );
  9.  
  10. // WP_Query arguments
  11. $args2 = array (
  12. 'post_type' => 'page',
  13. 'posts_per_page' => '5',
  14. 'meta_query' => array(
  15. array(
  16. 'key' => 'featured_page',
  17. 'value' => '1',
  18. 'compare' => '=='
  19. )
  20. ),
  21. );
  22.  
  23. // The Query
  24. $query1 = new WP_Query( $args1 );
  25. $query2 = new WP_Query( $args2 );
  26.  
  27. // create new empty query and populate it with the other two
  28. $wp_query = new WP_Query();
  29. $wp_query->posts = array_merge( $query1->posts, $query2->posts );
  30.  
  31. // populate post_count count for the loop to work correctly
  32. $wp_query->post_count = $query1->post_count + $query2->post_count;
  33.  
  34. // The Loop
  35. if ( $wp_query->have_posts() ) {
  36. echo '<div class="home-featured">';
  37.  
  38. while ( $wp_query->have_posts() ) {
  39. $wp_query->the_post();
  40.  
  41. echo '<div class="featured-item">';
  42.  
  43. $image = genesis_get_image( 'format=url&size=home-featured' );
  44.  
  45. printf( '<a href="%s" rel="bookmark"><img src="%s" alt="%s" /><h2 class="entry-title">%s</h2></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ), get_the_title() );
  46.  
  47. echo '</div>';
  48. }
  49.  
  50. echo '</div>';
  51. } else {
  52. // no posts found
  53. }
  54.  
  55. // Restore original Post Data
  56. wp_reset_postdata();
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement