SHARE
TWEET

Custom Loop

krishoja Jul 6th, 2016 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Outputs a custom loop
  3. */
  4. add_action( 'genesis_loop', 'genesis_kris_loop2' );
  5.             wp_reset_query();
  6.  
  7. function genesis_kris_loop2() {
  8.             $cat_order = get_field('category_order');
  9.             // get all the categories from the database
  10.       $cats = get_categories(       array (
  11.             'meta_key' => 'category_order',
  12.       'orderby'   => $cat_order, //or 'meta_value_num'
  13.             'count',
  14.             'posts_per_page' => -1,
  15.             'exclude' => '1, 7, 6, 8, 9, 10',
  16.             'order' => 'ASC',
  17.             ) );
  18.  
  19.                     // loop through the categries
  20.                     foreach ($cats as $cat) {
  21.                         // setup the cateogory ID
  22.                         $cat_id= $cat->term_id;
  23.                         // Make a header for the cateogry
  24.                         echo '<h2 class=slider-heading>'.$cat->name.'</h2>';
  25.                         echo '<div class="owl-demo">';
  26.                         // create a custom wordpress query
  27.                         query_posts("cat=$cat_id&post_type=case-study&post_per_page=-1&order=ASC"); //-1 shows all posts per category.
  28.                         // start the wordpress loop!
  29.         if (have_posts()) : while (have_posts()) : the_post();
  30.                 echo '<div class="item2"><a href="' . get_permalink() . '">';
  31.                     if ( has_post_thumbnail() ) {
  32.                             the_post_thumbnail('slide-thumb');
  33.                     }
  34.                   echo '<h3 class="bloghead2">';
  35.                    the_title();
  36.                    echo '</h3>';
  37.                   echo '</a></div>';
  38.                 endwhile;
  39.  
  40.                 endif; // done our wordpress loop. Will start again for each category ?>
  41.         </div>
  42.             <?php }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top