本文整理汇总了PHP中wp_query类的典型用法代码示例。如果您正苦于以下问题:PHP wp_query类的具体用法?PHP wp_query怎么用?PHP wp_query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了wp_query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: custom_query
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;
}
示例4: mbdmaster_latest_posts
/**
* 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();
}
}
示例5: 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;
}
示例6: ticker_function
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;
}
示例7: mbdmaster_related_posts
/**
* 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 :)';
}
}
示例8: mbdmaster_related_custom_posts
/**
* 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');
}
}
示例9: sidebars_remove
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: explode
<?php
if ($query != 'custom') {
if ($query == 'tag') {
$tags = explode(',', $tag);
foreach ($tags as $tag) {
$theTagId = get_term_by('name', $tag, 'post_tag');
if ($fea_tags) {
$sep = ' , ';
}
$fea_tags .= $sep . $theTagId->slug;
}
$args = array('tag' => $fea_tags, 'posts_per_page' => $number, 'no_found_rows' => 1);
} else {
$args = array('category__in' => $cat, 'posts_per_page' => $number, 'no_found_rows' => 1);
}
$breaking_query = new wp_query($args);
if ($breaking_query->have_posts()) {
$count = 0;
?>
<ul>
<?php
while ($breaking_query->have_posts()) {
$breaking_query->the_post();
$count++;
?>
<li><a href="<?php
the_permalink();
?>
" title="<?php
the_title();
?>
示例12: locate_template
<p>Tu solicitud se está tramitando en estos momentos. Te rogamos tengas paciencia.</p>
<?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>';
示例13: longform_the_related_posts
function longform_the_related_posts()
{
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' => 8, 'ignore_sticky_posts' => 1);
$my_query = new wp_query($args);
?>
<h2 class="related-articles-title"><?php
_e('Related articles', 'longform');
?>
</h2>
<div class="related-articles">
<?php
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div class="related-thumb col-sm-3 col-md-3 col-lg-3">
<a rel="external" href="<?php
the_permalink();
?>
">
<?php
the_post_thumbnail(array(500, 350));
?>
<div class="related-content">
<h2><?php
the_title();
?>
</h2>
</div>
</a>
</div>
<?php
}
?>
<div class="clearfix"></div>
</div>
<?php
}
wp_reset_postdata();
wp_reset_query();
}
示例14: evolve_similar_posts
function evolve_similar_posts()
{
$post = '';
$orig_post = $post;
global $post;
$evolve_similar_posts = evolve_get_option('evl_similar_posts', 'disable');
if ($evolve_similar_posts == "category") {
$matchby = get_the_category($post->ID);
$matchin = 'category';
} else {
$matchby = wp_get_post_tags($post->ID);
$matchin = 'tag';
}
if ($matchby) {
$matchby_ids = array();
foreach ($matchby as $individual_matchby) {
$matchby_ids[] = $individual_matchby->term_id;
}
$args = array($matchin . '__in' => $matchby_ids, 'post__not_in' => array($post->ID), 'showposts' => 5, 'ignore_sticky_posts' => 1);
$my_query = new wp_query($args);
if ($my_query->have_posts()) {
echo '<div class="similar-posts"><h5>' . __('Similar posts', 'evolve') . '</h5><ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li>
<a href="<?php
the_permalink();
?>
" rel="bookmark" title="<?php
_e('Permanent Link to', 'evolve');
?>
<?php
the_title();
?>
">
<?php
if (get_the_title()) {
$title = the_title('', '', false);
$evolve_posts_excerpt_title_length = intval(evolve_get_option('evl_posts_excerpt_title_length', '40'));
echo evolve_truncate($title, $evolve_posts_excerpt_title_length, '...');
} else {
echo __("Untitled", "evolve");
}
?>
</a>
<?php
if (get_the_content()) {
?>
—
<small><?php
echo evolve_excerpt_max_charlength(60);
?>
</small> <?php
}
?>
</li>
<?php
}
echo '</ul></div>';
}
}
$post = $orig_post;
wp_reset_query();
}
示例15: get_header
<?php
get_header();
/*
Template Name: People Page
*/
?>
<?php
$args = array('post_type' => 'people');
$people = new wp_query($args);
if ($people->have_posts()) {
while ($people->have_posts()) {
$people->the_post();
?>
<a class="btn btn-lg btn-primary" href="<?php
the_permalink();
?>
">
<img src="<?php
the_field('image');
?>
" alt="">
<?php
the_title();
?>
</a>