当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Query::have_posts方法代码示例

本文整理汇总了PHP中WP_Query::have_posts方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::have_posts方法的具体用法?PHP WP_Query::have_posts怎么用?PHP WP_Query::have_posts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Query的用法示例。


在下文中一共展示了WP_Query::have_posts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate_ryuzine_stylesheets

function generate_ryuzine_stylesheets()
{
    // verify this came from the our screen and with proper authorization.
    if (!wp_verify_nonce($_POST['ryu_regenstyles_noncename'], 'ryuzine-regenstyles_install')) {
        return;
    }
    // Check permissions
    if (!current_user_can('administrator')) {
        echo "<div class='error'><p>Sorry, you do not have the correct priveledges to install the files.</p></div>";
        return;
    }
    $my_query = null;
    $my_query = new WP_Query(array('post_type' => 'ryuzine'));
    if ($my_query->have_posts()) {
        while ($my_query->have_posts()) {
            $my_query->the_post();
            $stylesheet = "";
            $issuestyles = get_post_meta(get_the_ID(), '_ryustyles', false);
            if (!empty($issuestyles)) {
                foreach ($issuestyles as $appendstyle) {
                    // If there are multiple ryustyles append them //
                    $stylesheet = $stylesheet . $appendstyle;
                }
            }
            if ($stylesheet != "") {
                ryu_create_css($stylesheet, get_the_ID());
            }
        }
    }
    // reset css check //
    //	update_option('ryu_css_admin',0);
    wp_reset_query();
    return;
}
开发者ID:ryumaru,项目名称:ryuzine-press,代码行数:34,代码来源:rp_generate_css.php

示例2: bap_ajaxP_loop

function bap_ajaxP_loop($offset = '')
{
    global $wp_query;
    $paged = get_query_var('page') ? get_query_var('page') : 1;
    $do_not_duplicate = array();
    // OFFSET SETTING
    if (!$offset == '' || !$offset == '0') {
        $argshidepost = array('numberposts' => $offset, 'post_type' => 'post', 'post_status' => 'publish');
        $hide_to_array = get_posts($argshidepost);
        // HIDE OFFSETED POSTS
        if ($hide_to_array) {
            foreach ($hide_to_array as $post) {
                $do_not_duplicate[] = $post->ID;
            }
        }
    }
    $argsmain = array('post_type' => 'post', 'post_status' => 'publish', 'paged' => $paged, 'order' => 'DESC', 'post__not_in' => $do_not_duplicate);
    $wp_query = new WP_Query($argsmain);
    if ($wp_query->have_posts()) {
        echo '<section id="' . bap_get_option_text('bap_loopContainer') . '">';
        while ($wp_query->have_posts()) {
            $wp_query->the_post();
            get_template_part('partials/listitem');
        }
        echo '</section>';
    }
    wp_reset_postdata();
}
开发者ID:Aventyret,项目名称:bentoWP_plugin_AjaxPagin,代码行数:28,代码来源:bap_functions.php

示例3: get_Relationships_by_Tag

 public function get_Relationships_by_Tag($tag, $_method, $_route, $_path, $_headers)
 {
     if (empty($tag) || !is_string($tag)) {
         return new WP_Error('json_options_invalid_tag', __("Invalid options tag"), ['status' => 404]);
     }
     $site = $_headers['REMOTE'];
     $tags = explode(',', $tag);
     if ($tags) {
         $tags_query['relation'] = 'OR';
         foreach ($tags as $tag) {
             $tags_query[] = array('key' => 'related_tags', 'value' => $tag, 'compare' => 'LIKE');
         }
     }
     $args = array('post_type' => 'relationship', 'meta_query' => array('relation' => 'AND', array('key' => 'site_address', 'value' => $site), $tags_query));
     $relationships = new WP_Query($args);
     if ($relationships->have_posts()) {
         // Get the Target Categories
         $targets = [];
         while ($relationships->have_posts()) {
             $relationships->the_post();
             $targets[] = get_field('target_category');
         }
         $targets = dedupe($targets);
         $related_categories = implode(', ', $targets);
         // Find Matching Relationships
         $args = array('post_type' => 'relationship', 'tax_query' => array(array('taxonomy' => 'related_categories', 'terms' => $related_categories)));
         $relationships = new WP_Query($args);
         // Build Relationships JSON Reponse
         include 'related-json-response.php';
     }
     wp_reset_query();
     return $sites;
 }
开发者ID:fullsteamlabs,项目名称:root-around,代码行数:33,代码来源:class-root-around-relationships.php

示例4: widget

    function widget($args, $instance)
    {
        extract($args, EXTR_SKIP);
        $instance = wp_parse_args($instance, array('title' => __('Closed Questions', 'dwqa'), 'number' => 5));
        echo $before_widget;
        echo $before_title;
        echo $instance['title'];
        echo $after_title;
        $args = array('post_type' => 'dwqa-question', 'meta_query' => array('relation' => 'OR', array('key' => '_dwqa_status', 'compare' => '=', 'value' => 'resolved'), array('key' => '_dwqa_status', 'compare' => '=', 'value' => 'closed')));
        $questions = new WP_Query($args);
        if ($questions->have_posts()) {
            echo '<div class="dwqa-popular-questions">';
            echo '<ul>';
            while ($questions->have_posts()) {
                $questions->the_post();
                echo '
				<li><a href="' . get_permalink() . '" class="question-title">' . get_the_title() . '</a> ' . __('asked by', 'dwqa') . ' ' . get_the_author_link();
                '</li>';
            }
            echo '</ul>';
            echo '</div>';
        }
        wp_reset_query();
        wp_reset_postdata();
        echo $after_widget;
    }
开发者ID:Korotkin-Solutions,项目名称:dw-question-answer,代码行数:26,代码来源:list-closed-question.php

示例5: array

 function bl_posttype_shortcodes_showposts($params = array())
 {
     // Pulls the paramater values passed from the shortcode options
     extract(shortcode_atts(array('post_type' => 'post', 'post_status' => 'publish', 'offset' => 0, 'posts_per_page' => ''), $params));
     // Builds the query based on the available params
     $query = new WP_Query(array('post_type' => $post_type, 'post_status' => $post_status, 'offset' => $offset, 'posts_per_page' => $posts_per_page));
     // Looks for the presence of any qualifying posts inside the defined loop
     if ($query->have_posts()) {
         // We open the post container only where specified posts are available
         $shortcodeOutput = '<div>';
         while ($query->have_posts()) {
             $query->the_post();
             // Wraps each qualifying post for output in an <article> tag with Schema data.
             $shortcodeOutput .= '<article itemscope itemtype="http://schema.org/Article">';
             $shortcodeOutput .= '<a href="' . get_the_permalink() . '">';
             $shortcodeOutput .= '<h3 itemprop="name">' . get_the_title() . '</h3>';
             $shortcodeOutput .= '</a>';
             $shortcodeOutput .= '<time itemprop="dateCreated">' . get_the_date() . '</time>';
             $shortcodeOutput .= '<em itemprop="author">' . get_the_author() . '</em>';
             $shortcodeOutput .= '<div itemprop="description">' . get_the_excerpt() . '</div>';
             $shortcodeOutput .= '<article>';
         }
         // Closes off the parent container
         $shortcodeOutput .= '</div>';
     }
     // Resets the wordpress loop
     wp_reset_postdata();
     // Returns the concatenated shortcodeOutput to the page
     return $shortcodeOutput;
 }
开发者ID:benleah,项目名称:wp-posttype-shortcodes,代码行数:30,代码来源:class.bl-posttype-shortcodes.php

示例6: widget

    function widget($args, $instance)
    {
        global $post;
        // Preserve global $post
        $preserve = $post;
        extract($args);
        // only useful on post pages
        if (!is_single()) {
            return;
        }
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Read Next', 'largo') : $instance['title'], $instance, $this->id_base);
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        $related = new Largo_Related($instance['qty']);
        //get the related posts
        $rel_posts = new WP_Query(array('post__in' => $related->ids(), 'nopaging' => 1, 'posts_per_page' => $instance['qty'], 'ignore_sticky_posts' => 1));
        if ($rel_posts->have_posts()) {
            echo '<ul class="related">';
            while ($rel_posts->have_posts()) {
                $rel_posts->the_post();
                echo '<li>';
                echo '<a href="' . get_permalink() . '"/>' . get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class' => 'alignleft')) . '</a>';
                ?>
				<h4><a href="<?php 
                the_permalink();
                ?>
" title="Read: <?php 
                esc_attr(the_title('', '', FALSE));
                ?>
"><?php 
                the_title();
                ?>
</a></h4>
				<h5 class="byline">
					<span class="by-author"><?php 
                largo_byline(true, true);
                ?>
</span>
					<time class="entry-date updated dtstamp pubdate" datetime="<?php 
                echo esc_attr(get_the_date('c'));
                ?>
"><?php 
                largo_time();
                ?>
</time>
				</h5>
				<?php 
                // post excerpt/summary
                largo_excerpt(get_the_ID(), 2, false, '', true);
                echo '</li>';
            }
            echo "</ul>";
        }
        echo $after_widget;
        // Restore global $post
        wp_reset_postdata();
        $post = $preserve;
    }
开发者ID:NathanLawrence,项目名称:Largo,代码行数:60,代码来源:largo-related-posts.php

示例7: widget

 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     echo $args['before_widget'];
     if (!empty($instance['title'])) {
         echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
     }
     // The Query
     $query_args = array('post_type' => 'post', 'post_per_page' => 5, 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'ignore_sticky_posts' => 'true');
     $the_query = new WP_Query($query_args);
     // The Loop
     if ($the_query->have_posts()) {
         echo '<ul>';
         while ($the_query->have_posts()) {
             $the_query->the_post();
             echo '<li>';
             echo '<a href="' . get_the_permalink() . '" rel="bookmark">';
             echo get_the_title();
             echo '(' . get_post_meta(get_the_ID(), 'views', true) . ')';
             echo '</a>';
             echo '</li>';
         }
         echo '</ul>';
     } else {
         // no posts found
     }
     /* Restore original Post Data */
     wp_reset_postdata();
     echo $args['after_widget'];
 }
开发者ID:rajatahirqaiser,项目名称:Popular-Posts-WordPress-Plugin,代码行数:37,代码来源:popular-posts.php

示例8: array

 function ktz_mustread_content()
 {
     global $post;
     if (ot_get_option('ktz_popup_activated') == 'yes') {
         $paged = get_query_var('paged') ? get_query_var('paged') : 1;
         $args = array('post_type' => 'post', 'orderby' => 'rand', 'order' => 'desc', 'showposts' => 3, 'post_status' => 'publish', 'ignore_sticky_posts' => 1);
         $ktz_topfeatquery = new WP_Query($args);
         if ($ktz_topfeatquery->have_posts()) {
             echo '<div id="ktz_slidebox">';
             echo '<strong class="mustread_title">' . __('Must read', ktz_theme_textdomain) . '</strong><a href="#" class="close">&times;</a>';
             echo '<ul class="mustread_list">';
             while ($ktz_topfeatquery->have_posts()) {
                 $ktz_topfeatquery->the_post();
                 echo '<li class="mustread_li clearfix">';
                 echo '<div class="pull-left">';
                 echo ktz_featured_img(50, 50);
                 echo '</div>';
                 echo '<div class="title">';
                 echo ktz_posted_title_a();
                 echo '</div>';
                 echo '</li>';
             }
             echo '</ul>';
             echo '</div>';
         }
         wp_reset_query();
     }
 }
开发者ID:jjpango,项目名称:JJTeam,代码行数:28,代码来源:_slider_ktz.php

示例9: kool_preview_boxes

/**
 * kool_preview_boxes shows the next set of posts. It shows as many boxes as
 * you show posts on your blog page. This works best when there is an even
 * number of posts displayed (2,4,6,8,10) but it can work with an odd number
 * if alignment is set or if the width of boxes is set to 100% which would allow
 * for a column effct.
 * 
 * To use kool_preview simply add the function call in your theme's index after
 * the content is displayed. I could technically go before as well.      
 */
function kool_preview_boxes()
{
    global $post;
    if (is_paged()) {
        $target_page = get_query_var('paged') + 1;
    } else {
        $target_page = 2;
    }
    $args = array('paged' => $target_page, 'orderby' => 'post_date', 'post_type' => 'post', 'post_status' => 'publish');
    $k_posts = new WP_Query($args);
    if ($k_posts and $k_posts->have_posts()) {
        while ($k_posts->have_posts()) {
            $k_posts->the_post();
            $thumb_query = array('numberposts' => 1, 'post_type' => 'attachment', 'post_parent' => $post->ID);
            echo '<div class="preview_box" >';
            $attachment = get_posts($thumb_query);
            foreach ($attachment as $attach) {
                if ($attach) {
                    $img = wp_get_attachment_image_src($attach->ID, $size = 'thumbnail', $icon = true);
                    echo "<img class='preview_thumb' src='{$img['0']}' >";
                }
            }
            echo '<a rel="bookmark" href=';
            the_permalink();
            echo '>';
            echo the_title() . '</a><br>';
            the_excerpt();
            echo "</div>";
        }
    }
}
开发者ID:Nectarineimp,项目名称:Koolkit,代码行数:41,代码来源:koolFunctions.php

示例10: td_events_api

function td_events_api()
{
    $events = array();
    $start = isset($_GET['start']) ? $_GET['start'] : '';
    $end = isset($_GET['end']) ? $_GET['end'] : '';
    $args = array('post_type' => 'event');
    $query = new WP_Query($args);
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            $parent = get_post(get_post_meta(get_the_ID(), 'tdec_product', true));
            $dates = get_post_meta(get_the_ID(), 'tdec_dates', true);
            $color = get_post_meta(get_the_ID(), 'tdec_color', true);
            if (is_array($dates)) {
                foreach ($dates as $date) {
                    $event = array('title' => $parent->post_title, 'start' => date('c', $date['start']), 'end' => date('c', $date['end']), 'url' => get_permalink($parent->ID), 'backgroundColor' => $color);
                    $events[] = $event;
                }
            }
        }
    }
    wp_reset_postdata();
    echo json_encode($events);
    die;
}
开发者ID:NumanAfifi,项目名称:wp-demo,代码行数:25,代码来源:woocalendar.php

示例11: get_sliderobjects_array

function get_sliderobjects_array($slider)
{
    $category = get_field("categoria", $slider);
    $category_list = "";
    $return = array();
    $index = 0;
    for ($i = 0; $i < sizeof($category); $i++) {
        $category_list .= strlen($category_list) > 0 ? "," : "";
        $category_list .= $category[$i];
    }
    $option = get_field("opciones", $slider);
    //print_array($option);
    //print_array($category);
    // WP_Query arguments
    $args = array('post_type' => 'objeto', 'post_status' => 'publish', 'cat' => $category_list, 'order' => 'DESC', 'orderby' => 'date');
    // The Query
    $category_posts = new WP_Query($args);
    if ($category_posts->have_posts()) {
        while ($category_posts->have_posts()) {
            $category_posts->the_post();
            $return[$index] = get_the_ID();
            $index++;
        }
    }
    return $return;
}
开发者ID:eliascantoral,项目名称:guaflix,代码行数:26,代码来源:logic_.php

示例12: tpp_posts_widget

function tpp_posts_widget()
{
    $tpp_posts_query = new WP_Query();
    $tpp_posts_query->get_posts();
    ?>
	<h3>Posts on this page:</h3>
	<?php 
    if ($tpp_posts_query->have_posts()) {
        while ($tpp_posts_query->have_posts()) {
            $tpp_posts_query->the_post();
            ?>
	<a href="<?php 
            echo the_permalink();
            ?>
"
		title="<?php 
            echo the_title();
            ?>
"><?php 
            echo the_title();
            ?>
</a>
		(<?php 
            echo comments_number();
            ?>
)
	<?php 
        }
    }
    ?>
	<?php 
}
开发者ID:kirandash,项目名称:bijiplugindfly,代码行数:32,代码来源:top_posts_endStep1.php

示例13: widget

 /**
  * widget function.
  *
  * @see WP_Widget
  * @access public
  * @param array $args
  * @param array $instance
  * @return void
  */
 public function widget($args, $instance)
 {
     if ($this->get_cached_widget($args)) {
         return;
     }
     ob_start();
     extract($args);
     $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     $number = absint($instance['number']);
     add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
     $query_args = array('posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product');
     $query_args['meta_query'] = WC()->query->get_meta_query();
     $r = new WP_Query($query_args);
     if ($r->have_posts()) {
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         echo '<ul class="product_list_widget">';
         while ($r->have_posts()) {
             $r->the_post();
             wc_get_template('content-widget-product.php', array('show_rating' => true));
         }
         echo '</ul>';
         echo $after_widget;
     }
     remove_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
     wp_reset_postdata();
     $content = ob_get_clean();
     echo $content;
     $this->cache_widget($args, $content);
 }
开发者ID:devmoonshine,项目名称:development,代码行数:41,代码来源:widget-top-rated-products.php

示例14: Bing_sidebar_posts_list

/**
	*边栏文章列表
	*http://www.bgbk.org
*/
function Bing_sidebar_posts_list($query_args, $thumbnail = true)
{
    $query = new WP_Query($query_args);
    if ($query->have_posts()) {
        echo '<ul class="sidebar-posts-list">';
        while ($query->have_posts()) {
            $query->the_post();
            Bing_sidebar_posts_list_loop($thumbnail);
        }
        wp_reset_postdata();
        echo '</ul>';
    } else {
        ?>
		<div class="empty-sidebar-posts-list">
			<p><?php 
        _e('这里什么都没有,你也许可以使用搜索功能找到你需要的内容:');
        ?>
</p>
			<?php 
        get_search_form();
        ?>
		</div>
<?php 
    }
}
开发者ID:w392807287,项目名称:FirstRepository,代码行数:29,代码来源:posts-list.php

示例15: film_shortcode_query

function film_shortcode_query($atts, $content)
{
    extract(shortcode_atts(array('posts_per_page' => '1', 'post_type' => 'landing', 'caller_get_posts' => 1), $atts));
    global $post;
    $posts = new WP_Query($atts);
    $output = '';
    if ($posts->have_posts()) {
        while ($posts->have_posts()) {
            $posts->the_post();
            $out = '<div class="film_box">
                <h4>Film Name: <a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a></h4>
                <p class="Film_desc">' . get_the_content() . '</p>';
            // add here more...
            $out .= '</div>';
            /* these arguments will be available from inside $content
                   get_permalink()  
                   get_the_content()
                   get_the_category_list(', ')
                   get_the_title()
                   and custom fields
                   get_post_meta($post->ID, 'field_name', true);
               */
        }
    } else {
        return;
    }
    // no posts found
    wp_reset_query();
    return html_entity_decode($out);
}
开发者ID:futr3,项目名称:cdt-fsf,代码行数:30,代码来源:shortcodes.php


注:本文中的WP_Query::have_posts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。