コード例 #1
0
 /**
  * Query posts
  *
  * @global mixed $post
  * @param array $args
  * @param string $view_type
  * @return array
  */
 static function get_posts_list($args, $view_type)
 {
     // Store HTML output of each item
     $content_items = array();
     // The Query
     do_action(PT_CV_PREFIX_ . 'before_query');
     $pt_query = new WP_Query($args);
     //DEBUG_QUERY
     //print_r( $pt_query->request );
     do_action(PT_CV_PREFIX_ . 'after_query');
     // The Loop
     if ($pt_query->have_posts()) {
         while ($pt_query->have_posts()) {
             $pt_query->the_post();
             global $post;
             // Output HTML for this item
             $post_id = apply_filters(PT_CV_PREFIX_ . 'show_this_post', $post->ID);
             if ($post_id) {
                 $content_items[$post->ID] = PT_CV_Html::view_type_output($view_type, $post);
             }
         }
     } else {
         // Get no post found class
         $_class = apply_filters(PT_CV_PREFIX_ . 'content_no_post_found_class', 'alert alert-warning');
         // Get no post found text
         $_text = apply_filters(PT_CV_PREFIX_ . 'content_no_post_found_text', __('No post found', PT_CV_DOMAIN));
         // Output HTML
         $content_items[] = sprintf('<div class="%1$s">%2$s</div>', esc_attr($_class), balanceTags($_text));
     }
     // Restore $wp_query and original Post Data
     wp_reset_query();
     return array('content_items' => apply_filters(PT_CV_PREFIX_ . 'content_items', $content_items), 'pt_query' => $pt_query);
 }
コード例 #2
0
 /**
  * Query posts
  *
  * @global mixed $post
  * @param array $args
  * @param string $view_type
  * @return array
  */
 static function get_posts_list($args, $view_type)
 {
     $empty_result = false;
     // Store HTML output of each item
     $content_items = array();
     // The Query
     do_action(PT_CV_PREFIX_ . 'before_query');
     $pt_query = new WP_Query($args);
     do_action(PT_CV_PREFIX_ . 'after_query');
     //DEBUG_QUERY
     //print_r( $pt_query->request );
     // The Loop
     if ($pt_query->have_posts()) {
         do_action(PT_CV_PREFIX_ . 'before_process_item');
         $all_posts = array();
         $post_idx = 0;
         while ($pt_query->have_posts()) {
             $pt_query->the_post();
             global $post;
             // Output HTML for this item
             $_post = apply_filters(PT_CV_PREFIX_ . 'show_this_post', $post);
             if ($_post) {
                 $content_items[$post->ID] = PT_CV_Html::view_type_output($view_type, $post, $post_idx++);
                 $all_posts[$post->ID] = $post;
             }
         }
         $GLOBALS['cv_posts'] = $all_posts;
         do_action(PT_CV_PREFIX_ . 'after_process_item');
     } else {
         // Get no post found class
         $_class = apply_filters(PT_CV_PREFIX_ . 'content_no_post_found_class', 'alert alert-warning ' . PT_CV_PREFIX . 'no-post');
         // Get no post found text
         $_text = PT_CV_Html::no_post_found();
         // Output HTML
         $content_items[] = sprintf('<div class="%s">%s</div>', esc_attr($_class), $_text);
         $empty_result = true;
     }
     // Restore $wp_query and original Post data
     self::reset_query();
     return array('content_items' => apply_filters(PT_CV_PREFIX_ . 'content_items', $content_items, $view_type), 'pt_query' => $pt_query, 'empty_result' => $empty_result);
 }