本文整理汇总了PHP中query_posts函数的典型用法代码示例。如果您正苦于以下问题:PHP query_posts函数的具体用法?PHP query_posts怎么用?PHP query_posts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query_posts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: widget
function widget($args, $instance)
{
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? 'From The Blog' : $instance['title']);
$posts_number = empty($instance['posts_number']) ? '' : $instance['posts_number'];
$blog_category = empty($instance['blog_category']) ? '' : $instance['blog_category'];
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
?>
<ul>
<?php
query_posts("showposts=" . $posts_number . "&cat=" . $blog_category);
if (have_posts()) {
while (have_posts()) {
the_post();
?>
<li><a href="<?php
the_permalink();
?>
"><?php
the_title();
?>
</a></li>
<?php
}
}
wp_reset_query();
?>
</ul> <!-- end ul.nav -->
<?php
echo $after_widget;
}
示例2: 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;
}
echo '<ul>';
query_posts(array('post_type' => 'portfolio', 'showposts' => $number));
if (have_posts()) {
while (have_posts()) {
the_post();
?>
<li>
<a href="<?php
the_permalink();
?>
">
<?php
the_post_thumbnail('portfolio');
?>
</a>
</li>
<?php
}
}
wp_reset_query();
echo '</ul>';
echo $after_widget;
}
示例3: st_vc_blog
function st_vc_blog($attr, $content = false)
{
$data = shortcode_atts(array('st_blog_number_post' => 5, 'st_blog_orderby' => 0, 'st_blog_order' => '', 'st_blog_style' => '', 'st_category' => '', 'st_style' => 'style1'), $attr, 'st_blog');
extract($data);
$query = array('post_type' => 'post', 'orderby' => $st_blog_orderby, 'order' => $st_blog_order, 'posts_per_page' => $st_blog_number_post);
if ($st_category != '0' && $st_category != '') {
$query['tax_query'][] = array('taxonomy' => 'category', 'terms' => explode(',', $st_category));
}
query_posts($query);
$txt = '';
while (have_posts()) {
the_post();
if ($st_style == 'style1') {
$txt .= st()->load_template('vc-elements/st-blog/loop', false, $data);
}
if ($st_style == 'style2') {
$txt .= st()->load_template('vc-elements/st-blog/loop2', false, $data);
}
}
wp_reset_query();
$r = '<div class="row row-wrap">
' . $txt . '
</div>';
return $r;
}
示例4: test_redirection_with_asperand
function test_redirection_with_asperand()
{
$post_id = $this->factory->post->create(array('post_type' => 'post'));
$this->assertTrue($this->plugin()->set_link($post_id, 'http://example.com/@test'));
query_posts(array('p' => $post_id));
$this->assertEquals('http://example.com/%40test', $this->plugin()->get_redirect());
}
示例5: get_child_pages
function get_child_pages()
{
global $post;
rewind_posts();
//stops any previous loops
query_posts(array('post_type' => 'page', 'posts_per_page' => -1, 'post_status' => publish, 'post_parent' => $post->ID, 'order' => 'ASC', 'orderby' => 'menu_order'));
//query and order child pages
while (have_posts()) {
the_post();
$childPermalink = get_permalink($post->ID);
//post permalink
$childID = $post->ID;
//post it
$childTitle = $post->post_title;
//post title
$childExcerpt = $post->post_excerpt;
//post excerpt
$childImage = get_the_post_thumbnail($page->ID, 'featured-spotlight');
//post thumbnail
echo '<div class="tile">';
echo '<div class="tile-image">' . $childImage . '</div>';
echo '<h1 id="cta-h1"><a href="' . $childPermalink . '">' . $childTitle . '</a></h1>';
echo '<p class="caption"><a href="' . $childPermalink . '"><span>' . $childExcerpt . '</span></a></p>';
echo '</div>';
}
wp_reset_query();
// reset query
}
示例6: widget
function widget($args, $instance)
{
global $post, $wp_query;
Protect();
extract($args, EXTR_SKIP);
$post_query = 'showposts=1&cat=' . $instance['thecat'];
$posts =& query_posts($post_query);
if (have_posts()) {
while (have_posts()) {
the_post();
echo $before_widget;
$title = empty($instance['title']) ? 'Latest Excerpt' : apply_filters('widget_title', $instance['title']);
if (!empty($title)) {
echo $before_title . $title . $after_title;
}
?>
<ul>
<li><a href="<?php
the_permalink();
?>
"><?php
the_title();
?>
</a></li>
<li><?php
the_excerpt();
?>
</li>
</ul>
<?php
echo $after_widget;
}
}
UnProtect();
}
示例7: get_child_pages
function get_child_pages()
{
global $post;
rewind_posts();
// stop any previous loops
query_posts(array('post_type' => 'page', 'posts_per_page' => -1, 'post_status' => publish, 'post_parent' => $post->ID, 'order' => 'ASC', 'orderby' => 'menu_order'));
// query and order child pages
while (have_posts()) {
the_post();
$childPermalink = get_permalink($post->ID);
// post permalink
$childID = $post->ID;
// post id
$childTitle = $post->post_title;
// post title
$childExcerpt = $post->post_excerpt;
// post excerpt
echo '<article id="page-excerpt-' . $childID . '" class="page-excerpt">';
echo '<h3><a href="' . $childPermalink . '">' . $childTitle . ' »</a></h3>';
echo '<p>' . $childExcerpt . ' <a href="' . $childPermalink . '">Read More »</a></p>';
echo '</article>';
}
// reset query
wp_reset_query();
}
示例8: get
function get($queryArgs = null)
{
$defaults = array('post_type' => $this->name);
$paged = intval(get_query_var('paged'));
if ($paged) {
$defaults['paged'] = $paged;
}
if (isset($_GET[$this->name])) {
$defaults['name'] = sanitize_title($_GET[$this->name]);
} else {
$pagename = get_query_var('pagename');
if (!empty($pagename)) {
$defaults['name'] = sanitize_title($pagename);
}
}
$queryArgs = wp_parse_args($queryArgs, $defaults);
$posts = query_posts($queryArgs);
if (isset($queryArgs['name'])) {
$GLOBALS['wp_query']->is_single = true;
}
// remove the 404 from the main wp_query object
if (is_single() && !empty($post)) {
$GLOBALS['wp_query']->is_404 = false;
}
return $this->Query;
}
示例9: get_project_count
function get_project_count()
{
$showposts = -1;
$args = array('post_type' => 'projects', 'author' => $user_ID, 'orderby' => 'post_title', 'order' => 'ASC', 'post_status' => array('publish'), 'posts_per_page' => $showposts);
$count = count(query_posts($args));
return $count;
}
示例10: writeShoppingCart
function writeShoppingCart()
{
global $wpdb;
$settings = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "photocrati_ecommerce_settings WHERE id = 1", ARRAY_A);
foreach ($settings as $key => $value) {
${$key} = $value;
}
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p><em>' . $ecomm_empty . '</em> </p>';
} else {
// Parse the cart session variable
$items = explode(',', $cart);
$s = count($items) > 1 ? 's' : '';
if (get_option('permalink_structure') != '') {
return '<button id="addto2" class="positive" style="margin:0 5px;" onClick=\'window.location.href = "' . get_bloginfo('url') . '/' . str_replace(" ", "-", strtolower($ecomm_title)) . '/"\'><img src="' . photocrati_gallery_file_uri('image/cart.png') . '"> ' . $ecomm_title . ': ' . count($items) . ' item' . $s . '</button>';
} else {
$pgid = query_posts(array('pagename' => $ecomm_title));
foreach ($pgid as $pgid) {
$pageid = $pgid->ID;
}
wp_reset_query();
return '<button id="addto2" class="positive" style="margin:0 5px;" onClick=\'window.location.href = "' . get_bloginfo('url') . '/?page_id=' . $pageid . '"\'><img src="' . photocrati_gallery_file_uri('image/cart.png') . '"> ' . $ecomm_title . ': ' . count($items) . ' item' . $s . '</button>';
}
}
}
示例11: ajax_navigation_callback
function ajax_navigation_callback()
{
global $wp_query, $page_no, $loop, $query;
// this is how you get access to the database
$loop = empty($_POST['loop']) ? 'loop' : $_POST['loop'];
$posts_per_page = get_option('posts_per_page');
//merge the query array and paged
$query = $_POST;
unset($query['action']);
unset($query['loop']);
ob_start();
# Load the posts
if ($loop) {
query_posts($query);
while (have_posts()) {
the_post();
get_template_part($loop);
}
}
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
exit;
// this is required to return a proper result
}
示例12: categori_news
function categori_news(){
query_posts('cat=9&showposts=10&posts_per_page=3');
while (have_posts()) : the_post();
/*Dima insert*/the_excerpt(); ?>
<div class="content-box">
<div class="bgr01"><div class="bgr02"><div class="bgr03">
<div <?php post_class() ?> id="post-<?php the_ID(); ?>" style=" float:none; ">
<div class="title">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="date_all">
<?php the_time('l, j ?F, Y') ?>
</div>
<div class="post">
Написал <?php the_author_link() ?> <?php the_time('g:i A') ?>
</div>
</div>
<div class="content_box">
<?php the_content('Читать всё'); ?>
</div>
<div class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?></div>
<div class="comments"><?php comments_popup_link('0 комментарии', 'комментарии', '% комментарии '); ?></div>
<div class="link-edit"><?php edit_post_link('Edit', ''); ?></div>
</div>
</div></div></div>
</div>
<?php endwhile;}
示例13: show_category
function show_category($cid = 1)
{
$args = array('showposts' => 4, 'cat' => $cid, 'orderby' => 'post_date', 'order' => 'desc');
query_posts($args);
global $the_post;
$category = '';
while (have_posts()) {
the_post();
$cat = get_the_category(get_the_ID());
$link = get_permalink(get_the_ID());
$src = get_the_post_thumbnail(get_the_ID(), 'index_thumb');
$c_name = $cat[0]->name;
$title = get_the_title();
echo $category .= <<<EOF
<div class="box">
<a href="{$link}">
<div class="boximg">{$src}</div>
<div class="category">{$c_name}</div>
<p>{$title}</p>
</a>
</div>
EOF;
}
wp_reset_query();
return $category;
}
示例14: jigoshop_product_tag
function jigoshop_product_tag($attributes)
{
global $paged;
$jigoshop_options = Jigoshop_Base::get_options();
$attributes = shortcode_atts(array('tag' => '', 'per_page' => $jigoshop_options->get('jigoshop_catalog_per_page'), 'columns' => $jigoshop_options->get('jigoshop_catalog_columns'), 'orderby' => $jigoshop_options->get('jigoshop_catalog_sort_orderby'), 'order' => $jigoshop_options->get('jigoshop_catalog_sort_direction'), 'pagination' => false, 'tax_operator' => 'IN'), $attributes);
if (isset($_REQUEST['tag'])) {
$attributes['tag'] = $_REQUEST['tag'];
}
/** Operator validation. */
if (!in_array($attributes['tax_operator'], array('IN', 'NOT IN', 'AND'))) {
$tax_operator = 'IN';
}
/** Multiple category values. */
if (!empty($slug)) {
$slug = explode(',', esc_attr($slug));
$slug = array_map('trim', $slug);
}
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $attributes['per_page'], 'orderby' => $attributes['orderby'], 'order' => $attributes['order'], 'paged' => $paged, 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')), 'tax_query' => array(array('taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $attributes['tag'], 'operator' => $attributes['tax_operator'])));
query_posts($args);
ob_start();
jigoshop_get_template_part('loop', 'shop');
if ($attributes['pagination']) {
do_action('jigoshop_pagination');
}
wp_reset_query();
return ob_get_clean();
}
示例15: get_posts
/**
* Find all of the required posts
*
* @param array $content
* @return array
*/
public static function get_posts($content)
{
// Set up date filter
self::date_range($content['from_date'], $content['to_date']);
// Query parameters
$params = array('post_status' => 'future, publish', 'cat' => implode(',', $content['categories']), 'orderby' => 'date', 'order' => 'desc', 'posts_per_page' => $content['posts_number'] === 'All' ? self::$result_limit[$content['layout']] : 1);
// Get Posts
$query_results = query_posts($params);
// Remove filters and parameters to stop it from messing with our queries
wp_reset_query();
remove_filter('posts_where', array('Posts_Widget', 'date_filter'));
// Get custom fields for each post and filter
$results = array();
if (isset($content['filter_by']) && $content['filter_by'] === 'category') {
foreach ($query_results as $result) {
// Gets the posts categories
foreach (get_the_category($result->ID) as $cat) {
$result->fields = (object) get_fields($result->ID);
$results[$cat->cat_name][] = $result;
}
}
} else {
foreach ($query_results as $result) {
$year = mysql2date("Y", $result->post_date_gmt);
$result->fields = (object) get_fields($result->ID);
$results[$year][] = $result;
}
}
return $results;
}