本文整理汇总了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: home_banners_func
function home_banners_func($atts, $content = null)
{
// New function parameter $content is added!
extract(shortcode_atts(array('width' => '1/2', 'el_position' => '', 'section_height' => '', 'loop' => '', 'slideshow' => '', 'time' => '', 'transition_time' => ''), $atts));
$output = '';
global $post;
// get recent posts
$args = array('post_type' => 'banner', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'caller_get_posts' => 1);
$posts = new wp_query($args);
// if posts exist
if ($posts->have_posts()) {
$output .= '<section class="flexslider std-slider" data-height="' . $section_height . '" data-loop="' . $loop . '" data-smooth="false" data-slideshow="' . $slideshow . '" data-speed="' . $time . '" data-animspeed="' . $transition_time . '" data-controls="true" data-dircontrols="true">';
$output .= '<ul class="slides">';
// loop through and display them
while ($posts->have_posts()) {
$posts->the_post();
if (rwmb_meta('_wp_banner_image', $post->ID)) {
$images = rwmb_meta('_wp_banner_image', 'type=plupload_image', $post->ID);
if (count($images) > 0) {
foreach ($images as $image) {
$image_url = wp_get_attachment_image_src($image['ID'], 'full');
$output .= '<li data-bg="' . $image_url[0] . '">';
}
}
}
$output .= '<div class="container">';
$output .= '<div class="inner">';
$output .= '<div class="row">';
$output .= '<div class="text-center animated" data-fx="fadeIn">';
if (rwmb_meta('_wp_title', get_the_ID())) {
$output .= '<h2>' . rwmb_meta('_wp_title', get_the_ID()) . '</h2>';
}
if (rwmb_meta('_wp_sub_title', get_the_ID())) {
$output .= '<p>' . rwmb_meta('_wp_sub_title', get_the_ID()) . '</p>';
}
if (rwmb_meta('_wp_show_button_1', get_the_ID()) == 1) {
$output .= '<a href="' . rwmb_meta('_wp_button_1_url', get_the_ID()) . '" class="btn btn-primary btn-lg local">' . rwmb_meta('_wp_button_1_text', get_the_ID()) . '</a>';
}
if (rwmb_meta('_wp_show_button_2', get_the_ID()) == 1) {
$output .= '<a href="' . rwmb_meta('_wp_button_2_url', get_the_ID()) . '" class="btn btn-default btn-lg">' . rwmb_meta('_wp_button_2_text', get_the_ID()) . '</a>';
}
$output .= '</div>';
$output .= '<div class="col-md-6"></div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</section>';
}
wp_reset_query();
return $output;
}
示例2: extract
function custom_query($atts)
{
extract(shortcode_atts(array('query_string' => ''), $atts));
$result = '';
global $post;
$query = new wp_query($query_string);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$meta = get_post_meta($post->ID, 'thumbnail', true);
$result .= "<div class='post-item'>\n\t\t\t\t\t\t\t<a href=" . get_permalink() . "><img width='100' height='100' src=" . $meta . " /></a>\n\t\t\t\t\t\t\t<h1><a href=" . get_permalink() . ">" . get_the_title() . "</a></h1>\n\t\t\t\t\t\t\t<p class='metadata'><span class='post'>Posted by:</span>" . get_the_author() . "<span class='in-cat'>In:</span>" . get_the_category_list(', ') . "<span class='on-date'>On:</span>" . get_comment_time() . "<a href=" . get_comments_link() . ">" . get_comments_number('1 comment', '2 comment', '% comment') . "</a></p>\n\t\t\t\t\t\t\t<p>" . get_the_content() . "</p>\n\t\t\t\t\t\t\t<p><a class='more-link floatright' href=" . get_permalink() . ">Read More</a></p>\n\t\t\t\t\t\t</div>";
}
}
return $result;
}
示例3: array
/**
* Show the most recent posts
*/
function mbdmaster_latest_posts()
{
global $post;
$orig_post = $post;
$args = array('posts_per_page' => 3, 'ignore_sticky_posts' => 1);
$my_query = new wp_query($args);
if ($my_query->have_posts()) {
while ($my_query->have_posts()) {
$my_query->the_post();
get_template_part('content', 'archive');
}
$post = $orig_post;
wp_reset_query();
}
}
示例4: recent_projects_func
function recent_projects_func($atts, $content = null)
{
// New function parameter $content is added!
extract(shortcode_atts(array('width' => '1/2', 'el_position' => '', 'number' => ''), $atts));
$output = '';
global $post;
// get recent posts
$args = array('post_type' => 'portfolio', 'posts_per_page' => $number, 'caller_get_posts' => 1);
$portfolio_items = new wp_query($args);
// if posts exist
if ($portfolio_items->have_posts()) {
$output .= '<div id="galleryContainer" class="clearfix">';
// loop through and display them
while ($portfolio_items->have_posts()) {
$portfolio_items->the_post();
// find and display categories of portfolio items
$categories = get_the_terms(get_the_ID(), 'portfolio-category');
if ($categories && !is_wp_error($categories)) {
$cat_list = array();
$cat_list_slug = array();
foreach ($categories as $category) {
$cat_list[] = $category->name;
$cat_list_slug[] = $category->slug;
}
$types = join(" ", $cat_list_slug);
$types_comma = join(", ", $cat_list);
}
if (has_post_thumbnail()) {
$output .= '<div class="galleryItem ' . $types . '">';
$output .= '<a href="' . get_the_permalink() . '" class="area-hover">';
$output .= '<div class="vertical-parent">';
$output .= '<div class="vertical-child">';
$output .= '<span class="cat-links">' . $types_comma . '</span>';
$output .= '<h4 class="entry-title">' . get_the_title() . '</h4>';
$output .= '</div>';
$output .= '</div>';
$output .= '</a>';
$output .= '<a href="' . get_the_permalink() . '">' . get_the_post_thumbnail(get_the_ID(), 'related') . '</a>';
$output .= '</div>';
}
}
$output .= '</div>';
}
wp_reset_query();
return $output;
}
示例5: extract
function ticker_function($atts, $content)
{
extract(shortcode_atts(array('style' => 'left'), $atts));
?>
<div class="wd_sticker">
<?php
ob_start();
?>
<?php
$ticker = new wp_query(array('meta_key' => THEME_SLUG . 'showbreakingnews', 'ignore_sticky_posts' => 1, 'meta_value' => 1));
?>
<?php
if ($ticker->have_posts()) {
?>
<ul id="js-news" class="js-hidden">
<?php
while ($ticker->have_posts()) {
$ticker->the_post();
global $post;
?>
<li class="news-item"><?php
the_title();
?>
<a href="<?php
the_permalink();
?>
"><?php
_e('view more', 'wpdance');
?>
</a></li>
<?php
}
?>
</ul>
<?php
}
$result = ob_get_contents();
ob_end_clean();
wp_reset_postdata();
?>
</div>
<?php
return $result;
}
示例6: array
/**
* Show a set of related posts based on tags
*/
function mbdmaster_related_posts()
{
global $post;
$orig_post = $post;
$custom_taxterms = wp_get_object_terms($post->ID, 'post_tag', array('fields' => 'ids'));
$args = array('post_type' => array('award', 'book', 'interview', 'project', 'post', 'talk', 'film'), 'post__not_in' => array($post->ID), 'posts_per_page' => 3, 'ignore_sticky_posts' => 1, 'tax_query' => array(array('taxonomy' => 'post_tag', 'field' => 'id', 'terms' => $custom_taxterms)));
$my_query = new wp_query($args);
if ($my_query->have_posts()) {
while ($my_query->have_posts()) {
$my_query->the_post();
get_template_part('content', 'archive');
}
$post = $orig_post;
wp_reset_query();
} else {
echo 'Nothing found... Looks like this post is just unique :)';
}
}
示例7: array
/**
* Show a set of related posts based on a custom taxonomy
*/
function mbdmaster_related_custom_posts()
{
global $post;
$orig_post = $post;
$custom_taxterms = wp_get_object_terms($post->ID, 'tag', array('fields' => 'ids'));
$args = array('post_type' => 'work', 'post_status' => 'publish', 'posts_per_page' => 3, 'orderby' => 'rand', 'tax_query' => array(array('taxonomy' => 'tag', 'field' => 'id', 'terms' => $custom_taxterms)), 'post__not_in' => array($post->ID));
$my_query = new wp_query($args);
if ($my_query->have_posts()) {
while ($my_query->have_posts()) {
$my_query->the_post();
get_template_part('content', 'archive');
}
$post = $orig_post;
wp_reset_query();
} else {
_e('Sorry, but there is no related work at this time.', '_mbdmaster');
}
}
示例8: lasso_editor_galleries_exist
/**
* Check to see if any Lasso galleries exist
*
* @since 1.0
*/
function lasso_editor_galleries_exist()
{
$q = new wp_query(array('post_type' => 'ai_galleries', 'post_status' => 'publish'));
if ($q->have_posts()) {
return true;
} else {
return false;
}
}
示例9: array
function sidebars_remove($sidebar_id, $default_id = null)
{
global $post;
$data_return = array();
$wp_query_pages = new wp_query(array('showposts' => -1, 'post_type' => 'page'));
while ($wp_query_pages->have_posts()) {
$wp_query_pages->the_post();
$page_custom_meta = get_post_custom($post->ID);
if (is_array($page_custom_meta) && array_key_exists('_ewf-page-sidebar', $page_custom_meta)) {
if ($page_custom_meta["_ewf-page-sidebar"][0] == $sidebar_id) {
$data_return[$post->ID] = "true";
update_post_meta($post->ID, "_ewf-page-sidebar", $default_id);
} else {
$data_return[$post->ID] = "false";
}
}
}
wp_reset_postdata();
return $data_return;
}
示例10: agatha_postsrelacionados
function agatha_postsrelacionados()
{
$orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach ($tags as $individual_tag) {
$tag_ids[] = $individual_tag->term_id;
}
$args = array('tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page' => 4, 'caller_get_posts' => 1);
$my_query = new wp_query($args);
?>
<section id="relatedPost">
<?php
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div class="col-md-3 col-xs-6 relatedPost">
<a rel="external" href="<?php
the_permalink();
?>
"><?php
the_post_thumbnail('miniatura');
?>
<br />
<?php
the_title();
?>
</a>
</div>
<?php
}
?>
</section>
<?php
}
$post = $orig_post;
wp_reset_query();
}
示例11: array
<?php
include locate_template('templates/sections/section-close.php');
?>
</div>
<?php
}
?>
<?php
if ($user_info->ID == get_current_user_id() && !is_user_role('subscriber')) {
?>
<?php
$args = array('order' => 'DESC', 'posts_per_page' => -1, 'post_type' => 'fee', 'orderby' => 'meta_value', 'meta_key' => 'fee_date_end');
$fee_query = new wp_query($args);
if ($fee_query->have_posts()) {
$html_info = '';
$html_warning = '';
while ($fee_query->have_posts()) {
$fee_query->the_post();
$fee_date_start = get_post_meta(get_the_ID(), 'fee_date_start', true);
$fee_date_end = get_post_meta(get_the_ID(), 'fee_date_end', true);
if (strtotime($fee_date_start) < time() && strtotime($fee_date_end) > time()) {
$members_payed = is_array(get_post_meta(get_the_ID(), 'members_payed', true)) ? get_post_meta(get_the_ID(), 'members_payed', true) : array();
$members_pending = is_array(get_post_meta(get_the_ID(), 'members_pending', true)) ? get_post_meta(get_the_ID(), 'members_pending', true) : array();
if ($members_payed[get_current_user_id()] == '') {
if ($members_pending[get_current_user_id()] != '') {
$html_info .= '<p>Cuota <a href="' . get_the_permalink() . '">' . get_the_title() . '</a> en proceso de validación</p>';
} else {
$html_warning .= '<p>Cuota <a href="' . get_the_permalink() . '">' . get_the_title() . '</a> pendiente de abono.</p>';
}
示例12: widget
function widget($args, $instance)
{
extract($args);
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
if (!empty($title)) {
if (!empty($instance['postlink'])) {
if (get_option('show_on_front') == 'page') {
$link = get_permalink(get_option('page_for_posts'));
} else {
$link = get_permalink(get_option('home'));
}
$before_title .= '<a href="' . $link . '">';
$after_title .= '</a>';
}
echo $before_title . $title . $after_title;
}
$ul_classes = 'recent_posts_with_excerpts';
$ul_classes = apply_filters('recent_posts_with_excerpts_list_classes', $ul_classes);
if (!empty($ul_classes)) {
$ul_classes = ' class="' . $ul_classes . '"';
}
$li_classes = '';
$li_classes = apply_filters('recent_posts_with_excerpts_item_classes', $li_classes);
if (!empty($li_classes)) {
$li_classes = ' class="' . $li_classes . '"';
}
$h2_classes = 'recent_posts_with_excerpts';
$h2_classes = apply_filters('recent_posts_with_excerpts_heading_classes', $h2_classes);
if (!empty($h2_classes)) {
$h2_classes = ' class="' . $h2_classes . '"';
}
do_action('recent_posts_with_excerpts_begin');
echo '<ul' . $ul_classes . '>';
// retrieve last n blog posts
$q = array('posts_per_page' => $instance['numposts']);
if (!empty($instance['ignore_sticky_posts'])) {
$q["ignore_sticky_posts"] = $instance['ignore_sticky_posts'];
}
if (!empty($instance['cat'])) {
$q['cat'] = $instance['cat'];
}
if (!empty($instance['offset']) && $instance['offset'] > 0) {
$q['offset'] = $instance['offset'];
}
if (!empty($instance['tag'])) {
$q['tag'] = $instance['tag'];
}
$q = apply_filters('recent_posts_with_excerpts_query', $q);
$rpwe = new wp_query($q);
$excerpts = $instance['numexcerpts'];
$date = apply_filters('recent_posts_with_excerpts_date_format', $instance['date']);
// the Loop
if ($rpwe->have_posts()) {
while ($rpwe->have_posts()) {
$rpwe->the_post();
echo '<li' . $li_classes . '>';
if ($excerpts > 0 && $instance['thumb'] && $instance['thumbposition'] == 'above') {
echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail(get_the_id(), $instance['thumbsize']) . '</a>';
}
echo '<h2' . $h2_classes . '><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
if (!empty($date)) {
echo '<h3 class="date">' . get_the_time($date) . '</h3>';
}
if ($excerpts > 0) {
// show the excerpt
if ($instance['thumb'] && $instance['thumbposition'] == 'between') {
echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail(get_the_id(), $instance['thumbsize']) . '</a>';
}
?>
<blockquote> <?php
// the excerpt of the post
if (function_exists('the_excerpt_reloaded')) {
the_excerpt_reloaded($instance['words'], $instance['tags'], 'content', FALSE, '', '', '1', '');
} else {
the_excerpt();
}
// this covers Advanced Excerpt as well as the built-in one
if (!empty($instance['more_text'])) {
?>
<p class="alignright"><small><a href="<?php
the_permalink();
?>
"><?php
echo $instance['more_text'];
}
?>
</a></small></p>
</blockquote> <?php
if ($excerpts > 0 && $instance['thumb'] && $instance['thumbposition'] == 'below') {
echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail(get_the_id(), $instance['thumbsize']) . '</a>';
}
$excerpts--;
}
?>
</li>
<?php
}
}
?>
//.........这里部分代码省略.........
示例13: navigation
}
}
?>
<!-- tabbed content -->
<div class="tabbed-content post-tabs clear-block" id="post-tabs">
<?php
if ($jquery && ($comments || comments_open() || pings_open() && $numPingBacks > 0)) {
// no tabs if jquery is disabled
?>
<!-- tab navigation (items must be in reverse order because of the tab-design) -->
<div class="tabs-wrap clear-block">
<ul class="tabs">
<?php
if ($rp_query && $rp_query->have_posts()) {
?>
<li class="related-posts"><a href="#section-relatedPosts"><span><?php
_e('Related Posts', 'mystique');
?>
</span></a></li><?php
}
?>
<?php
if ($numPingBacks > 0) {
?>
<li class="trackbacks"><a href="#section-trackbacks"><span><?php
printf(__('Trackbacks (%s)', 'mystique'), $numPingBacks);
?>
</span></a></li><?php
}
示例14: xborders_post_related
function xborders_post_related()
{
$orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach ($categories as $individual_category) {
$category_ids[] = $individual_category->term_id;
}
$args = array('category__in' => $category_ids, 'post__not_in' => array($post->ID), 'posts_per_page' => 5, 'caller_get_posts' => 1, 'orderby' => 'rand');
$my_query = new wp_query($args);
if ($my_query->have_posts()) {
echo '<div id="xborders_related">';
echo '<span>Similar Post</span>';
echo '<div id="thumbnail_posts" class="clearfix">';
echo '<div class="container">';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div class="row">
<div class="col-md-2 col-sm-6 col-xs-12 text-left">
<a href="<?php
the_permalink();
?>
" rel="bookmark" title="<?php
the_title();
?>
">
<span class="h-thumnail">
<?php
the_post_thumbnail(array(60, 60), array('class' => 'img-responsive'));
?>
</span>
</a>
</div>
<div class="col-md-10 cok-sm-6 col-xs-12 blog-title text-left">
<a href="<?php
the_permalink();
?>
" rel="bookmark" title="<?php
the_title();
?>
">
<span class="h-title">
<?php
the_title();
?>
</span>
</a>
</div>
</div>
<?php
}
echo '</div></div>';
}
}
$post = $orig_post;
wp_reset_query();
}
示例15: array
esc_html_e('Similar Properties', 'reales');
?>
</h3>
<?php
$orig_post = $post;
$orig_city = get_post_meta($post->ID, 'property_city', true);
$orig_category = wp_get_post_terms($post->ID, 'property_category', array('fields' => 'ids'));
$orig_type = wp_get_post_terms($post->ID, 'property_type_category', array('fields' => 'ids'));
$exclude_ids = array($post->ID);
$args = array('posts_per_page' => 4, 'post_type' => 'property', 'post_status' => 'publish', 'post__not_in' => $exclude_ids);
if ($orig_type && $orig_category) {
$args['tax_query'] = array('relation' => 'AND', array('taxonomy' => 'property_category', 'field' => 'id', 'terms' => $orig_category[0]), array('taxonomy' => 'property_type_category', 'field' => 'id', 'terms' => $orig_type[0]));
}
$args['meta_query'] = array(array('key' => 'property_city', 'value' => $orig_city));
$my_query = new wp_query($args);
if ($my_query->have_posts() && $orig_type && $orig_category) {
?>
<div class="row">
<?php
while ($my_query->have_posts()) {
$my_query->the_post();
$s_id = get_the_ID();
$s_link = get_permalink($s_id);
$s_title = get_the_title($s_id);
$s_gallery = get_post_meta($s_id, 'property_gallery', true);
$s_images = explode("~~~", $s_gallery);
$s_price = get_post_meta($s_id, 'property_price', true);
$reales_general_settings = get_option('reales_general_settings');
$s_currency = isset($reales_general_settings['reales_currency_symbol_field']) ? $reales_general_settings['reales_currency_symbol_field'] : '';
$s_currency_pos = isset($reales_general_settings['reales_currency_symbol_pos_field']) ? $reales_general_settings['reales_currency_symbol_pos_field'] : '';
$s_price_label = get_post_meta($s_id, 'property_price_label', true);