steve-acet

Shortcode with exclude post ids

Mar 10th, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2. function displayChildPage($atts){
  3.    extract(shortcode_atts(array(
  4.       'parent' => '',
  5.       'icon' => false,
  6.       'exclude' => ''
  7.    ), $atts));
  8.  
  9.     wp_reset_postdata();
  10.  
  11.     global $post;
  12.    
  13.     if (empty($parent))
  14.         $parent = $post->ID;
  15.    
  16.     $output = "";
  17.    
  18.     $args = array(
  19.     'orderby'       => 'menu_order',
  20.     'order'         => 'ASC',
  21.     'post_parent__in' => explode( ",", $parent),
  22.     'post_type'     => 'page',
  23.     'post_status'   => 'publish',
  24.     'numberposts'   => 24,
  25.     'post__not_in'  => explode(",",$exclude)
  26.     );
  27.     $query = new WP_Query( $args );
  28.    
  29.     if ( $query->have_posts() ) :
  30.         $i = 0;
  31.        
  32.         while ( $query->have_posts() ) {
  33.             $query->the_post();
  34.         if($i % 4 == 0) {
  35.             if($i > 0) {
  36.                 $output .= '</div>';
  37.             }
  38.             $output .= '<div class="row no-margin gutters split-extra-small">';
  39.         }
  40.         $output .= '<article id="post-' . get_the_ID() . '" class="' . implode(' ', get_post_class('column-6 grid match glow text-center',  get_the_ID())) . '">';
  41.            
  42.             $thumb_id = get_post_thumbnail_id();
  43.             $thumb_url = wp_get_attachment_image_src($thumb_id,'medium', true);  
  44.            
  45.             if ($thumb_id) {
  46.                 $output .= '<a href="' . get_permalink() . '"><img src="'. $thumb_url[0] . '" alt="' . get_the_title(get_the_ID())  . '" /></a>';
  47.             } else {
  48.                 $output .= '<a href="' . get_permalink() . '"><span class="fa-stack fa-3x"><i class="fa fa-circle fa-stack-2x"></i><i class="icon icon-' . $post->post_name . '  fa-stack-1x"></i></span></a>';
  49.             }
  50.             $output .= '<h3 class="entry-title"><a href="' . get_permalink() . '" rel="bookmark">' . get_the_title(get_the_ID()) . '</a></h3>';
  51.        
  52.         $output .= '</article><!-- #post-## -->';
  53.        
  54.                    
  55.         $i++;
  56.         }
  57.         $output .= '</div>';
  58.         $output .= '<!-- subPage -->';
  59.  
  60.     endif;
  61. // 
  62.     wp_reset_postdata();
  63.    
  64.     return $output;
  65. }
  66. add_shortcode('childPage', 'displayChildPage');
Advertisement
Add Comment
Please, Sign In to add comment