本文整理汇总了PHP中WP_Query类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query类的具体用法?PHP WP_Query怎么用?PHP WP_Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Query类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: charity_vc_our_mission
function charity_vc_our_mission($atts, $content = null)
{
extract(shortcode_atts(array('our_mission' => ''), $atts));
$page_id = get_page_by_title($our_mission);
$missionQuery = new WP_Query(array("page_id" => $page_id->ID));
if ($missionQuery->have_posts()) {
$missionQuery->the_post();
$url = wp_get_attachment_image_src(get_post_thumbnail_id($page_id->ID), array(1143, 479));
?>
<!-- Save Lives Section Start Here-->
<section class="save-lives text-center parallax" style="background-image: url('<?php
echo esc_url($url[0]);
?>
')">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<header class="page-header">
<h2><?php
the_title();
?>
</h2>
<?php
the_content();
?>
</header>
</div>
</div>
</div>
</section>
<!-- Save Lives Section Start Here-->
<?php
}
wp_reset_postdata();
}
开发者ID:kautzar,项目名称:drpp4,代码行数:35,代码来源:our-mission.php
示例2: widget
function widget($args, $instance)
{
global $post;
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? __('Recent Posts', 'lan-thinkupthemes') : apply_filters('widget_title', $instance['title']);
if (!empty($title)) {
echo $before_title . $title . $after_title;
}
$posts = new WP_Query('orderby=date&posts_per_page=' . $instance['postcount'] . '');
while ($posts->have_posts()) {
$posts->the_post();
// Insert post date if needed.
if ($instance['postdate'] == 'on') {
$date_input = '<a href="' . get_permalink() . '" class="date">' . get_the_date('M j, Y') . '</a>';
}
// HTML output
echo '<div class="recent-posts">';
if (has_post_thumbnail() and $instance['imageswitch'] == 'on') {
echo '<div class="image">', '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_post_thumbnail($post->ID, array(65, 65)) . '<div class="image-overlay"></div></a>', '</div>', '<div class="main">', '<a href="' . get_permalink() . '">' . get_the_title() . '</a>', $date_input, '</div>';
} else {
echo '<div class="main">', '<a href="' . get_permalink() . '">' . get_the_title() . '</a>', $date_input, '</div>';
}
echo '</div>';
}
wp_reset_query();
echo $after_widget;
}
开发者ID:closings,项目名称:closings,代码行数:28,代码来源:recentposts.php
示例3: load_user
public function load_user()
{
if ($this->id > 0) {
$current_user = get_user_by('ID', $this->id);
} elseif (function_exists('is_user_logged_in') && is_user_logged_in()) {
$current_user = wp_get_current_user();
}
if (isset($current_user) && $current_user) {
$this->id = $current_user->ID;
$this->first_name = $current_user->user_firstname;
$this->last_name = $current_user->user_lastname;
$this->email = $current_user->user_email;
$this->address = get_user_meta($current_user->ID, 'address', TRUE);
$this->is_on_mailing_list = get_user_meta($current_user->ID, 'mailing_list', TRUE);
$this->is_on_mailing_list = $this->is_on_mailing_list == 1 ? TRUE : FALSE;
$neighborhood_id = get_user_meta($current_user->ID, 'neighborhood_id', TRUE);
if (!empty($neighborhood_id) && $neighborhood_id > 0) {
$args = array('post_type' => 'wbb_neighborhood', 'post_status' => 'publish');
$query = new \WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
if (get_the_ID() == $neighborhood_id) {
$this->neighborhood = new Neighborhood();
$this->neighborhood->post_id = get_the_ID();
$this->neighborhood->title = get_the_title();
break;
}
}
}
$this->get_locations();
}
}
开发者ID:TonyDeStefano,项目名称:Walk-Bike-Bus-Plugin,代码行数:32,代码来源:User.php
示例4: 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
示例5: 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
示例6: 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
示例7: parse_query
/**
* Hook into the query parsing to detect oEmbed requests.
*
* If an oEmbed request is made, trigger the output.
*
* @codeCoverageIgnore
*
* @param WP_Query $wp_query The WP_Query instance (passed by reference).
*/
public function parse_query($wp_query)
{
// Check for required params.
if (false === $wp_query->get('oembed', false)) {
return;
}
if (false === $wp_query->get('url', false)) {
status_header(400);
echo 'URL parameter missing';
exit;
}
/**
* Check for the allowed query vars and set defaults.
*
* @see WP_REST_oEmbed_Controller::register_routes()
*/
$url = esc_url_raw(get_query_var('url'));
$format = sanitize_text_field(get_query_var('format', 'json'));
/**
* Filter the maxwidth oEmbed parameter.
*
* @param int $maxwidth Maximum allowed width. Defaults to 600.
*
* @return int
*/
$maxwidth = apply_filters('oembed_default_width', 600);
$maxwidth = get_query_var('maxwidth', $maxwidth);
$callback = get_query_var('_jsonp', false);
$request = array('url' => $url, 'format' => $format, 'maxwidth' => $maxwidth, 'callback' => $callback);
echo $this->dispatch($request);
exit;
}
开发者ID:noplanman,项目名称:oEmbed-API,代码行数:41,代码来源:class-wp-legacy-oembed-controller.php
示例8: get_pins
public static function get_pins($args)
{
$defaults = array('numberposts' => 5, 'category' => 0, 'orderby' => 'date', 'order' => 'DESC', 'include' => array(), 'exclude' => array(), 'meta_key' => '', 'meta_value' => '', 'post_type' => 'pin', 'suppress_filters' => true);
$p = wp_parse_args($args, $defaults);
$get_pins = new WP_Query();
return $get_pins->query($p);
}
开发者ID:rwrobe,项目名称:restful_maps,代码行数:7,代码来源:Pins.php
示例9: rec_epl_lu_single_download
function rec_epl_lu_single_download()
{
global $post, $epl_settings;
$unique_id = get_post_meta($post->ID, 'property_unique_id', true);
$tab_title = isset($epl_settings['epl_lu_group_title']) ? __($epl_settings['epl_lu_group_title'], 'epl') : __('Extra Info', 'epl');
$query = new WP_Query(array('post_type' => 'listing_unlimited', 'meta_query' => array(array('key' => 'property_unique_id', 'value' => $unique_id, 'compare' => '=='))));
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$link = get_post_meta($post->ID, 'listing_unlimited_pdf', true);
?>
<div style="xxxdisplay:none" class="rec-panel-section-32 xxxfancybox-hidden">
<div id="xxxfancyboxID-section-32">
<?php
echo do_shortcode('[gravityform id="21" title="false" description="false" tabindex="33"]');
?>
</div>
</div>
<!--<h5 class="widget-sub-title download"><a href="#fancyboxID-section-32" class="rec-panel-section-32-popout-fancybox fancybox"><i class="fa fa-file-pdf-o"></i> Download Section 32</a></h5>-->
<?php
}
}
wp_reset_postdata();
}
开发者ID:easypropertylistings,项目名称:library,代码行数:26,代码来源:template-functions-ash.php
示例10: wptouch_custom_latest_post_filter
function wptouch_custom_latest_post_filter($query_vars)
{
if (wptouch_is_showing_mobile_theme_on_mobile_device()) {
$settings = foundation_get_settings();
if (foundation_is_theme_using_module('custom-latest-posts') && $settings->latest_posts_page != 'none') {
$dummy_query = new WP_Query();
// the query isn't run if we don't pass any query vars
$dummy_query->parse_query($query_vars);
if ($dummy_query->is_page && count($query_vars) == 0) {
// Front page
$front_option = get_option('show_on_front', false);
if ($front_option == 'page') {
$front_page = get_option('page_on_front');
$dummy_query->queried_object_id = $front_page;
}
}
if (isset($dummy_query->queried_object_id) && apply_filters('foundation_is_custom_latest_posts_page', $settings->latest_posts_page == $dummy_query->queried_object_id)) {
if (isset($query_vars['paged'])) {
$paged = $query_vars['paged'];
} elseif (isset($query_vars['page'])) {
$paged = $query_vars['page'];
} else {
$paged = 1;
}
$query_vars = array('paged' => $paged, 'posts_per_page' => $settings->posts_per_page);
// Since we're modifying the query here, we need to prevent the custom landing page redirect from firing for this request (it'll think it's loading the homepage)
add_filter('wptouch_redirect_target', 'wptouch_return_false');
}
}
}
return $query_vars;
}
开发者ID:yarylo,项目名称:cerkva.pp.ua,代码行数:32,代码来源:custom-latest-posts.php
示例11: pricetable
/**
*
*/
public static function pricetable($atts, $content = null, $code = null)
{
if ($atts == 'generator') {
global $wpdb;
$prices_list = array();
$pricetables = $wpdb->get_results('SELECT ID, post_title FROM ' . $wpdb->posts . ' WHERE post_type = "pricetable"');
if (is_array($pricetables)) {
foreach ($pricetables as $key => $value) {
$prices_list[$value->ID] = $pricetables[$key]->post_title;
}
} else {
$price_list[0] = __('Please install Price Table plugin...', MISS_ADMIN_TEXTDOMAIN);
}
$option = array('name' => __('Blog Grid Layout', MISS_ADMIN_TEXTDOMAIN), 'value' => 'pricetable', 'options' => array(array('name' => __('Select Table', MISS_ADMIN_TEXTDOMAIN), 'desc' => __('Choose "Pricing Table" to use.', MISS_ADMIN_TEXTDOMAIN), 'id' => 'id', 'type' => 'select', 'options' => $prices_list), 'shortcode_has_atts' => true));
return $option;
}
extract(shortcode_atts(array('id' => ''), $atts));
$pricetable = new WP_Query();
$pricetable->query(array('post_type' => 'pricetable', 'post_id' => $id));
while ($pricetable->have_posts()) {
$pricetable->the_post();
$prices_list[get_the_ID()] = get_the_title();
$out = '[price_table id="' . $id . '"]';
}
return do_shortcode($out);
}
开发者ID:schiz,项目名称:scrollax,代码行数:29,代码来源:pricetable.php
示例12: widget
function widget($args, $instance)
{
$cache = wp_cache_get('widget_dt_slider', 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (!isset($args['widget_id'])) {
$args['widget_id'] = $this->id;
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
ob_start();
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('', 'engine') : $instance['title'], $instance, $this->id_base);
$category = empty($instance['category']) ? '' : $instance['category'];
$qty = empty($instance['qty']) ? '3' : $instance['qty'];
$excerpt_length = empty($instance['excerpt_length']) ? '0' : $instance['excerpt_length'];
$r = new WP_Query(array('posts_per_page' => $qty, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category__in' => explode(',', $category)));
if ($r->have_posts()) {
?>
<?php
echo $before_widget;
echo do_shortcode('[engine_slider title="' . $title . '" category="' . $category . '" qty="' . $qty . '" autoplay="0" random="0" thumb_size="small" excerpt_length="' . $excerpt_length . '"]');
echo $after_widget;
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
}
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_dt_slider', $cache, 'widget');
}
开发者ID:wangshijun101,项目名称:morketing.cn,代码行数:32,代码来源:dt-slider.php
示例13: wp_ajax_load_posts
/**
* Ajax function for loading posts by date and category
*/
function wp_ajax_load_posts()
{
if (!wp_verify_nonce($_GET['_wpnonce'], 'nonce-ajax-dropdown')) {
die('Go away!');
}
$year = isset($_GET['year']) ? $_GET['year'] : '';
$month = isset($_GET['month']) ? $_GET['month'] : '';
$args = array('year' => trim($year), 'monthnum' => trim($month), 'posts_per_page' => -1, 'orderby' => 'date', 'cat' => trim($_GET['cat'] != "-1") ? trim($_GET['cat']) : 0);
$ajaxsort = new WP_Query($args);
?>
<?php
if ($ajaxsort->have_posts()) {
?>
</div>
<?php
while ($ajaxsort->have_posts()) {
$ajaxsort->the_post();
?>
<?php
get_template_part('content', 'archives');
?>
<?php
}
?>
<?php
} else {
echo '<div align="center">Nothing Found!</div></nav>';
}
exit;
}
开发者ID:katstar01,项目名称:fivebeers,代码行数:34,代码来源:archives.php
示例14: widget
/**
* Display widget content.
*
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The settings for the particular instance of the widget
*/
function widget($args, $instance)
{
extract($args);
$instance = wp_parse_args((array) $instance, $this->defaults);
$featured_page = new WP_Query(array('page_id' => $instance['page_id']));
echo $before_widget . '<div class="feature-page">';
if (!empty($instance['title'])) {
echo $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title;
}
if ($featured_page->have_posts()) {
while ($featured_page->have_posts()) {
$featured_page->the_post();
echo '<div class="' . implode(' ', get_post_class()) . '">';
if (!empty($instance['show_title'])) {
printf('<h4 class="entry-title"><a href="%s" title="%s">%s</a></h4>', get_permalink(), the_title_attribute('echo=0'), get_the_title());
}
//Show image
if (!empty($instance['show_image'])) {
printf('<a href="%s" title="%s" class="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), esc_attr($instance['image_alignment']), calibrefx_get_image(array('format' => 'html', 'size' => $instance['image_size'])));
}
if (!empty($instance['show_content'])) {
if (empty($instance['content_limit'])) {
the_content($instance['more_text']);
} else {
the_content_limit((int) $instance['content_limit'], esc_html($instance['more_text']));
}
}
echo '</div><!--end post_class()-->' . "\n\n";
}
}
echo '</div>' . $after_widget;
wp_reset_query();
}
开发者ID:alispx,项目名称:calibrefx,代码行数:39,代码来源:feature_page_widget.php
示例15: 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
示例16: ktz_mustread_content
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">×</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
示例17: blog_summary_shortcode
function blog_summary_shortcode($attr)
{
// Describes what attributes to parse from shortcode; only 'count'
extract(shortcode_atts(array('count' => '5', 'grouptag' => 'ul', 'entrytag' => 'li', 'titletag' => 'h4', 'datetag' => 'span', 'commentstag' => 'span', 'summarytag' => 'div'), $attr));
// Queries to populate our loop based on shortcode count attribute
$r = new WP_Query("showposts={$count}&what_to_show=posts&nopaging=0&post_status=publish");
// Only run if we have posts; can't run this through searches
if ($r->have_posts() && !is_search()) {
// If we're using a Sandbox-friendly theme . . .
if (function_exists('sandbox_body_class')) {
// We can't have double hfeed classes, otherwise it won't parse
$groupclasses = 'xoxo';
} else {
// Otherwise, use hfeed to ensure hAtom compliance
$groupclasses = 'xoxo hfeed';
}
// Begin the output for shortcode and inserts in the group tag what classes we have
$output = '<' . $grouptag . ' class="' . $groupclasses . '">';
// Begins our loop for returning posts
while ($r->have_posts()) {
// Sets which post from our loop we're at
$r->the_post();
// Allows the_date() with multiple posts within a single day
unset($previousday);
// If we're using a Sandbox-friendly theme . . .
if (function_exists('sandbox_post_class')) {
// Let's use semantic classes with each entry element
$entryclasses = sandbox_post_class(false);
} else {
// Otherwise, use hentry to ensure hAtom compliance
$entryclasses = 'hentry';
}
// Begin entry wrapper and inserts what classes we got from above
$output .= "\n" . '<' . $entrytag . ' class="' . $entryclasses . '">';
// Post title
$output .= "\n" . '<' . $titletag . ' class="entry-title"><a href="' . get_permalink() . '" title="' . sprintf(__('Permalink to %s', 'blog_summary'), the_title_attribute('echo=0')) . '" rel="bookmark">' . get_the_title() . '</a></' . $titletag . '>';
// Post date with hAtom support
$output .= "\n" . '<' . $datetag . ' class="entry-date"><abbr class="published" title="' . get_the_time('Y-m-d\\TH:i:sO') . '">' . sprintf(__('%s', 'blog_summary'), the_date('', '', '', false)) . '</abbr></' . $datetag . '>';
// Comments number
$output .= "\n" . '<' . $commentstag . ' class="entry-comments"><a href="' . get_permalink() . '#comments" title="' . sprintf(__('Comments to %s', 'blog_summary'), the_title_attribute('echo=0')) . '">' . sprintf(__('Comments (%s)', 'blog_summary'), apply_filters('comments_number', get_comments_number())) . '</a></' . $commentstag . '>';
// Post excerpt with hAtom support
$output .= "\n" . '<' . $summarytag . ' class="entry-summary">' . "\n" . apply_filters('the_excerpt', get_the_excerpt()) . '</' . $summarytag . '>';
// Close each post LI
$output .= "\n" . '</' . $entrytag . '>';
// Finish the have_posts() query
}
// while ( $r->have_posts() ) :
// Close the parent UL
$output .= "\n" . '</' . $grouptag . '>';
// Rewinds loop from $r->the_post();
rewind_posts();
// End the initial IF statement
}
// if ( $r->have_posts() ) :
// Clears our query to put the loop back where it was
wp_reset_query();
// $r = new WP_Query()
// Returns $output to the shortcode
return $output;
}
开发者ID:Turante,项目名称:wp-plugin-dev,代码行数:60,代码来源:blog-summary.php
示例18: theme_posts_shortcode
/**
* Shortcode functionality to show posts.
*
* @since 1.0.0
*/
function theme_posts_shortcode($atts)
{
$output = false;
// Pull in shortcode attributes and set defaults
$defaults = array('category' => '', 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => '10', 'tag' => '');
// Process shortcode attribtues
$atts = shortcode_atts($defaults, $atts, 'show-posts');
// Set up initial query for post
$args = array('category_name' => $atts['category'], 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'posts_per_page' => $atts['posts_per_page'], 'tag' => $atts['tag'], 'ignore_sticky_posts' => 1, 'no_found_rows' => true);
$query = new WP_Query($args);
if ($query->have_posts()) {
global $wp_query;
// Backup the main query.
$saved_query = $wp_query;
// Replace the main query by reference.
$wp_query = $query;
// Capture the output so we can return it to the shortcode process.
ob_start();
echo '<div class="show-posts-wrapper">';
while ($wp_query->have_posts()) {
$wp_query->the_post();
get_template_part('content', get_post_format());
}
echo '</div>';
$output = ob_get_clean();
// Clean up after ourselves.
$wp_query = $saved_query;
wp_reset_postdata();
}
return $output;
}
开发者ID:joemcgill,项目名称:Theme-Posts-Shortcode,代码行数:36,代码来源:theme-posts-shortcode.php
示例19: widget
function widget($args, $instance)
{
extract($args);
$title = apply_filters('widget_title', $instance['title']);
$number = $instance['number'];
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
?>
<div class="recent-works-items clearfix">
<?php
$args = array('post_type' => 'evolve_portfolio', 'posts_per_page' => $number, 'has_password' => false);
$portfolio = new WP_Query($args);
if ($portfolio->have_posts()) {
?>
<?php
while ($portfolio->have_posts()) {
$portfolio->the_post();
?>
<?php
if (has_post_thumbnail()) {
?>
<?php
$link_target = "";
$url_check = get_post_meta(get_the_ID(), 'pyre_link_icon_url', true);
if (!empty($url_check)) {
$new_permalink = get_post_meta(get_the_ID(), 'pyre_link_icon_url', true);
if (get_post_meta(get_the_ID(), 'pyre_link_icon_target', true) == "yes") {
$link_target = ' target="_blank"';
}
} else {
$new_permalink = get_permalink();
}
?>
<a href="<?php
echo $new_permalink;
?>
"<?php
echo $link_target;
?>
title="<?php
the_title();
?>
">
<?php
the_post_thumbnail('recent-works-thumbnail');
?>
</a>
<?php
}
}
}
wp_reset_query();
?>
</div>
<?php
echo $after_widget;
}
开发者ID:berniecultess,项目名称:infirev,代码行数:60,代码来源:recent-works-widget.php
示例20: parse_query
/**
* Hook into the query parsing to detect oEmbed requests.
*
* If an oEmbed request is made, trigger the output.
*
* @since 4.4.0
*
* @param WP_Query $wp_query The WP_Query instance (passed by reference).
*/
public function parse_query($wp_query)
{
if (false === $wp_query->get('oembed', false)) {
return;
}
if (false === $wp_query->get('url', false)) {
status_header(400);
echo 'URL parameter missing';
exit;
}
$url = esc_url_raw(get_query_var('url'));
$format = wp_oembed_ensure_format(get_query_var('format'));
/**
* Filter the maxwidth oEmbed parameter.
*
* @since 4.4.0
*
* @param int $maxwidth Maximum allowed width. Default 600.
*/
$maxwidth = apply_filters('oembed_default_width', 600);
$maxwidth = absint(get_query_var('maxwidth', $maxwidth));
$callback = get_query_var('_jsonp', false);
$request = array('url' => $url, 'format' => $format, 'maxwidth' => $maxwidth, 'callback' => $callback);
echo $this->dispatch($request);
exit;
}
开发者ID:hadywisam,项目名称:WordPress,代码行数:35,代码来源:class-wp-oembed-controller.php
注:本文中的WP_Query类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论