本文整理汇总了PHP中WP_query类的典型用法代码示例。如果您正苦于以下问题:PHP WP_query类的具体用法?PHP WP_query怎么用?PHP WP_query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: subpage_peek
function subpage_peek($atts, $content = null)
{
global $post;
// Extract shortcode arguements
extract(shortcode_atts(array('order' => 'asc', 'orderby' => 'menu_order', 'numpages' => '-1', 'hidethumb' => 'false', 'removelinks' => 'false', 'showfullcontent' => 'false'), $atts));
//query subpages
$args = array('post_parent' => $post->ID, 'post_type' => 'page', 'order' => $order, 'orderby' => $orderby, 'posts_per_page' => $numpages);
$subpages = new WP_query($args);
$i = 1;
// create output
if ($subpages->have_posts()) {
$output = '<div id="subpage-list">';
while ($subpages->have_posts()) {
$subpages->the_post();
$output .= '<hr /><div class="entry" id="subpage-link-' . $i . '">';
if ($hidethumb == 'false' && has_post_thumbnail()) {
// check if the post has a Post Thumbnail assigned to it.
$output .= '<a href="' . get_permalink() . '" class="alignleft">' . get_the_post_thumbnail($post->ID, 'thumbnail', array('class' => 'wp-post-image')) . '</a>';
}
$output .= '<h3>';
$output .= $removelinks == 'true' ? get_the_title() : '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
$output .= '</h3><p>';
$output .= $showfullcontent == 'true' ? get_the_content() : get_the_excerpt();
if ($removelinks == 'false') {
$output .= '<br /><a href="' . get_permalink() . '"><em>Read more »</em></a>';
}
$output .= '</p>
</div>';
$i++;
}
$output .= '<div style="clear:both;"></div>';
$output .= '</div>';
} else {
$output = '<p>No subpages found.</p>';
}
// reset the query
wp_reset_postdata();
// return something
return $output;
}
示例2: image_cpt_shortcode
function image_cpt_shortcode($attr)
{
if ($attr['page'] <= 10) {
$per_page['page'] = $attr['page'];
} else {
$per_page['page'] = 10;
}
$output = '<h2 class="winner-title">Hall of Winners</h2><h3 class="winner-subtitle">Congratulations to all of our winners</h3>';
$args = array('post_type' => 'image_post_type', 'posts_per_page' => $per_page['page']);
$loop = new WP_query($args);
if ($loop->have_posts()) {
while ($loop->have_posts()) {
$loop->the_post();
$output .= '<div class="winner-div"><h3>';
$output .= get_the_title();
$output .= '</h3>';
if (has_post_thumbnail()) {
// check if the post has a post thumbnail assigned to it.
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($loop->ID), 'full');
$url = $thumb['0'];
$output .= '<img src="' . $url . '"/>';
}
$output .= '</div>';
}
} else {
// if no content, include the "no posts found" template.
get_template_part('content', 'none');
}
return $output;
}
示例3: widget
function widget($args, $instance)
{
extract($args);
$category = isset($instance['category']) ? $instance['category'] : '';
$postcount = empty($instance['postcount']) ? '5' : $instance['postcount'];
$offset = empty($instance['offset']) ? '' : $instance['offset'];
$sticky = isset($instance['sticky']) ? $instance['sticky'] : 0;
echo $before_widget;
?>
<section id="slider-<?php
echo rand(1, 9999);
?>
" class="flexslider">
<ul class="slides"><?php
$args = array('posts_per_page' => $postcount, 'cat' => $category, 'offset' => $offset, 'ignore_sticky_posts' => $sticky);
$slider = new WP_query($args);
while ($slider->have_posts()) {
$slider->the_post();
?>
<li>
<article class="slide-wrap">
<div class="mh-slider-overlay"></div>
<a href="<?php
the_permalink();
?>
" title="<?php
the_title_attribute();
?>
"><?php
if (has_post_thumbnail()) {
the_post_thumbnail('content');
} else {
echo '<img src="' . get_template_directory_uri() . '/images/noimage_content.png' . '" alt="No Picture" />';
}
?>
</a>
<header class="slide-caption">
<a href="<?php
the_permalink();
?>
" title="<?php
the_title_attribute();
?>
"><h2 class="slide-title"><?php
the_title();
?>
</h2></a>
</header>
</article>
</li><?php
}
wp_reset_postdata();
?>
</ul>
</section><?php
echo $after_widget;
}
示例4: wp_stripe_options_display_projects
/**
* Projects - Display projects within options page
*/
function wp_stripe_options_display_projects()
{
// Query Custom Post Types
$args = array('post_type' => 'wp-stripe-projects', 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => 'wp-stripe-completion', 'order' => 'ASC', 'posts_per_page' => 50);
// - query -
$my_query = null;
$my_query = new WP_query($args);
while ($my_query->have_posts()) {
$my_query->the_post();
$time_format = get_option('time_format');
// - variables -
$custom = get_post_custom(get_the_ID());
$id = $my_query->post->ID;
$public = $custom["wp-stripe-public"][0];
$live = $custom["wp-stripe-live"][0];
$name = $custom["wp-stripe-name"][0];
$email = $custom["wp-stripe-email"][0];
$content = get_the_content();
$date = $custom["wp-stripe-date"][0];
$cleandate = date('d M', $date);
$cleantime = date('H:i', $date);
$amount = $custom["wp-stripe-amount"][0];
$fee = $custom["wp-stripe-fee"][0] / 100;
$net = round($amount - $fee, 2);
echo '<tr>';
// Dot
if ($live == 'LIVE') {
$dotlive = '<div class="dot-stripe-live"></div>';
} else {
$dotlive = '<div class="dot-stripe-test"></div>';
}
if ($public == 'YES') {
$dotpublic = '<div class="dot-stripe-public"></div>';
} else {
$dotpublic = '<div class="dot-stripe-test"></div>';
}
// Person
$img = get_avatar($email, 32);
$person = $img . ' <span class="stripe-name">' . $name . '</span>';
// Received
$received = '<span class="stripe-netamount"> + ' . $net . '</span> (-' . $fee . ')';
// Content
echo '<td>' . $dotlive . $dotpublic . '</td>';
echo '<td>' . $person . '</td>';
echo '<td>' . $received . '</td>';
echo '<td>' . $cleandate . ' - ' . $cleantime . '</td>';
echo '<td class="stripe-comment">"' . $content . '"</td>';
echo '</tr>';
}
}
示例5: mon_espace_pub_show
function mon_espace_pub_show()
{
$args = array('post_type' => 'slider', 'ignore_sticky_posts' => true);
$pub = new WP_query($args);
if ($pub->have_posts()) {
echo "<div id='pub'>";
while ($pub->have_posts()) {
$pub->the_post();
echo "<div class='la_pub'>";
the_post_thumbnail('slider');
echo "</div>";
}
echo "</div>";
wp_reset_postdata();
}
}
示例6: SPD2012_insertPage
/**
* Create a shortcode to insert content of a page of specified ID
*
* @param array attributes of shortcode
* @return string $output Content of page specified, if no page id specified output = null
*/
function SPD2012_insertPage($atts, $content = null)
{
// Default output if no pageid given
$output = NULL;
// extract atts and assign to array
extract(shortcode_atts(array("page" => ''), $atts));
// if a page id is specified, then run query
if (!empty($page)) {
$pageContent = new WP_query();
$pageContent->query(array('pagename' => $page));
while ($pageContent->have_posts()) {
$pageContent->the_post();
// assign the content to $output
$output = get_the_content();
}
}
return $output;
}
示例7: suffusion_get_headlines
/**
* Magazine template function to get headlines
*
* @return array
*/
function suffusion_get_headlines()
{
global $post, $wpdb, $suf_mag_headline_limit;
$headlines = array();
$solos = array();
$suf_mag_headline_limit = (int) $suf_mag_headline_limit;
$quota_full = false;
// Previously the script was loading all posts into memory using get_posts and checking the meta field. This causes the code to crash if the # posts is high.
$querystr = "SELECT wposts.*\n\t\tFROM {$wpdb->posts} wposts, {$wpdb->postmeta} wpostmeta\n\t\tWHERE wposts.ID = wpostmeta.post_id\n\t AND wpostmeta.meta_key = 'suf_magazine_headline'\n\t AND wpostmeta.meta_value = 'on'\n\t AND wposts.post_status = 'publish'\n\t AND wposts.post_type = 'post'\n\t ORDER BY wposts.post_date DESC\n\t ";
$head_posts = $wpdb->get_results($querystr, OBJECT);
foreach ($head_posts as $post) {
setup_postdata($post);
$headlines[] = $post;
$solos[] = $post->ID;
if (count($headlines) == $suf_mag_headline_limit) {
$quota_full = true;
break;
}
}
if ($quota_full) {
return $headlines;
}
$headline_categories = suffusion_get_allowed_categories('suf_mag_headline_categories');
if (is_array($headline_categories) && count($headline_categories) > 0) {
$query_cats = array();
foreach ($headline_categories as $headline_category) {
$query_cats[] = $headline_category->cat_ID;
}
$query_posts = implode(",", array_values($query_cats));
$cat_query = new WP_query(array('cat' => $query_posts, 'post__not_in' => $solos));
}
if (isset($cat_query->posts) && is_array($cat_query->posts)) {
while ($cat_query->have_posts()) {
$cat_query->the_post();
$headlines[] = $post;
if (count($headlines) == $suf_mag_headline_limit) {
$quota_full = true;
break;
}
}
}
return $headlines;
}
示例8: my_diapordg_show
/**
* Permet d'afficher le carrousel
**/
function my_diapordg_show($limit = 8)
{
//on importe le JS
wp_deregister_script('jquery');
wp_enqueue_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js', null, '5.6.4', true);
wp_enqueue_script('caroufredsel', plugins_url() . '/exro/js/jquery.carouFredSel-6.0.4-packed.js', array('jquery'), '5.6.4', true);
add_action('wp_footer', 'my_diapordg_script', 30);
//On écrit le Html
$slides = new WP_query('post_type=slide&posts_per_page=' . $limit);
echo "<div id='my_diapordg'>";
while ($slides->have_posts()) {
$slides->the_post();
global $post;
echo '<a style="display:block; float:left; height:200;" href="' . esc_attr(get_post_meta($post->ID, '_link', true)) . '">';
the_post_thumbnail('slider', array('style' => 'width:200px!important;'));
echo '</a>';
}
echo "</div>";
}
示例9: get_header
*
* @package SKT Healing Touch
*/
get_header();
?>
<div class="all-box">
<div class="feature-box-main site-aligner">
<?php
for ($f = 1; $f < 5; $f++) {
?>
<?php
if (get_theme_mod('page-setting' . $f)) {
?>
<?php
$queryvar = new WP_query('page_id=' . get_theme_mod('page-setting' . $f, true));
?>
<?php
while ($queryvar->have_posts()) {
$queryvar->the_post();
?>
<div class="feature-box <?php
if ($f % 4 == 0) {
?>
last<?php
}
?>
">
<?php
the_post_thumbnail();
?>
示例10: ot_get_option
/* ]]> */
</script>
<?php
if (ot_get_option('news-category-title')) {
?>
<span class="breaking"> <?php
echo ot_get_option('news-category-title');
?>
</span><?php
}
?>
<ul id="ticker">
<?php
$newscategory = ot_get_option('news-category');
$categorynum = ot_get_option('news-category-num');
$queryObject = new WP_query(array('category__and' => $newscategory, 'posts_per_page' => $categorynum));
if ($queryObject->have_posts()) {
while ($queryObject->have_posts()) {
$queryObject->the_post();
?>
<li><a href="<?php
the_permalink();
?>
"><span><time class="post_date date updated" datetime="<?php
the_time('j M, Y');
?>
"><?php
echo time_ago();
?>
</time></span> <b class="post-title entry-title"><?php
the_title();
示例11: WP_query
<?php
if (!isset($module_query_args)) {
return;
}
$the_query = new WP_query($module_query_args);
if ($the_query->have_posts()) {
?>
<div class="module">
<?php
if (isset($module_query_args['fw_heading']['title'])) {
$module_title = $module_query_args['fw_heading']['title'];
if (isset($module_query_args['fw_heading']['link'])) {
//die(var_dump($module_query_args['fw_heading']['link']));
$module_title = '<a href="' . $module_query_args['fw_heading']['link'] . '">' . $module_title . '<i class="skin-icon skin-icon-plus"></i></a>';
}
echo '<div class="module-heading">' . '<h3 class="module-title">' . $module_title . '</h3>' . '</div>';
}
?>
<?php
while ($the_query->have_posts()) {
$the_query->the_post();
?>
<?php
/**
* Exclude these post in home page listing
*/
if (isset($post_to_exclude) && !in_array($post->ID, $post_to_exclude)) {
$post_to_exclude[] = $post->ID;
}
?>
示例12: WP_query
</h2>
<p><?php
echo 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis malesuada ex non magna convallis aliquam. Nulla ullamcorper elit a ante ullamcorper, nec malesuada <br> massa commodo. In ut nisi nisl. Nullam porta fringilla purus, quis mollis enim tincidunt ut. Praesent vitae lacus ligula. Aliquam efficitur pharetra mauris, in molestie arcu<br> efficitur ornare. Vivamus sed finibus felis, nec cursus lorem.';
?>
</p>
<?php
}
/*Home Section Content*/
?>
<div class="clear"></div>
<?php
/* Home Four Boxes */
for ($bx = 2; $bx < 6; $bx++) {
if (get_theme_mod('page-setting' . $bx)) {
$bxquery = new WP_query('page_id=' . get_theme_mod('page-setting' . $bx, true));
while ($bxquery->have_posts()) {
$bxquery->the_post();
?>
<a href="<?php
the_permalink();
?>
"><div class="feature-box">
<?php
the_post_thumbnail();
?>
<h2><?php
the_title();
?>
</h2>
<?php
示例13: get_header
/**
* Template Name: Navigation-sub
*/
get_header();
?>
<div id="primary" class="content-area interview">
<main id="main" class="site-main" role="main">
<?php
if (function_exists('dimox_breadcrumbs')) {
dimox_breadcrumbs();
}
?>
<?php
$args = array('post_parent' => 103, 'post_type' => 'page', 'paged' => $paged);
$subpages = new WP_query($args);
if ($subpages->have_posts()) {
$output = '<ul class="menu-event-wrapp">';
while ($subpages->have_posts()) {
$subpages->the_post();
$output .= '<li><div class="thumb"><a href="' . get_permalink() . '">' . get_the_post_thumbnail() . '</a></div></li>';
}
$output .= '</ul>';
}
echo $output;
wp_reset_postdata();
?>
<?php
$title = get_the_title();
$temp = get_cat_ID($title);
if ($title == 'Інтерв’ю') {
示例14: WP_query
<?php
if (is_front_page() && !is_home()) {
?>
<section id="wrapsecond" class="pagewrap2">
<div class="container services-wrap">
<?php
for ($p = 1; $p < 5; $p++) {
?>
<?php
if (get_theme_mod('page-column' . $p, false)) {
?>
<?php
$queryxxx = new WP_query('page_id=' . get_theme_mod('page-column' . $p, true));
?>
<?php
while ($queryxxx->have_posts()) {
$queryxxx->the_post();
?>
<div class="listpages <?php
if ($p % 4 == 0) {
echo "last_column";
}
?>
">
<a href="<?php
the_permalink();
示例15: wp_stripe_options_display_trx
/**
* Display Transctions on Options Page
*
* @since 1.0
*
*/
function wp_stripe_options_display_trx()
{
// Paging
function retrievePage()
{
if (!isset($_POST['pagination']) || $_POST['pagination'] == "1") {
$paged = 1;
} else {
$paged = $_POST['pagination'];
}
return intval($paged);
}
// Query Custom Post Types
$args = array('post_type' => 'wp-stripe-trx', 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => 'wp-stripe-date', 'order' => 'DESC', 'posts_per_page' => 10, 'paged' => retrievePage());
// - query -
$my_query = null;
$my_query = new WP_query($args);
while ($my_query->have_posts()) {
$my_query->the_post();
$time_format = get_option('time_format');
// - variables -
$custom = get_post_custom(get_the_ID());
$id = $my_query->post->ID;
$public = $custom["wp-stripe-public"][0];
$live = $custom["wp-stripe-live"][0];
$name = $custom["wp-stripe-name"][0];
$email = $custom["wp-stripe-email"][0];
$content = get_the_content();
$date = $custom["wp-stripe-date"][0];
$cleandate = date('d M', $date);
$cleantime = date('H:i', $date);
$amount = $custom["wp-stripe-amount"][0];
$fee = $custom["wp-stripe-fee"][0] / 100;
$currency = $custom['wp-stripe-currency'][0];
$net = round($amount - $fee, 2);
echo '<tr>';
// Dot
if ($live == 'LIVE') {
$dotlive = '<div class="dot-stripe-live"></div>';
} else {
$dotlive = '<div class="dot-stripe-test"></div>';
}
if ($public == 'YES') {
$dotpublic = '<div class="dot-stripe-public"></div>';
} else {
$dotpublic = '<div class="dot-stripe-test"></div>';
}
// Person
$img = get_avatar($email, 32);
$person = $img . ' <span class="stripe-name">' . $name . '</span>';
// Received
$received = '<span class="stripe-netamount"> + ' . $net . '</span> ' . $currency . ' (-' . $fee . ')';
// Content
echo '<td>' . $dotlive . $dotpublic . '</td>';
echo '<td>' . $person . '</td>';
echo '<td>' . $received . '</td>';
echo '<td>' . $cleandate . ' - ' . $cleantime . '</td>';
echo '<td class="stripe-comment">"' . $content . '"</td>';
echo '</tr>';
}
?>
</table>
<div style="clear:both"></div>
<?php
function totalPages($transactions)
{
// get total pages
if ($transactions > 0) {
$totalpages = floor($transactions / 10) + 1;
} else {
return;
}
return $totalpages;
}
$currentpage = retrievePage();
$totalpages = totalPages($my_query->found_posts);
if ($currentpage > 1) {
echo '<form method="POST" class="pagination">';
echo '<input type="hidden" name="pagination" value="' . (retrievePage() - 1) . '" />';
echo '<input type="submit" value="Previous 10" />';
echo '</form>';
}
if ($currentpage < $totalpages) {
echo '<form method="POST" class="pagination">';
echo '<input type="hidden" name="pagination" value="' . (retrievePage() + 1) . '" />';
echo '<input type="submit" value="Next 10" />';
echo '</form>';
}
echo ' <div style="clear:both"></div>';
}