本文整理汇总了PHP中WP_Query::posts_count方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::posts_count方法的具体用法?PHP WP_Query::posts_count怎么用?PHP WP_Query::posts_count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::posts_count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract
function portfolio_item($atts, $content)
{
extract(shortcode_atts(array('id' => '', 'slug' => ''), $atts));
$query = '';
if (!post_type_exists('portfolio')) {
return;
}
if (absint($id) > 0) {
$query = new WP_Query(array('post_type' => 'portfolio', 'post__in' => array($id)));
} elseif (strlen(trim($slug)) > 0) {
$_post = get_page_by_path($slug, OBJECT, 'portfolio');
if (!is_null($_post)) {
$query = new WP_Query(array('post_type' => 'portfolio', 'post__in' => array($_post->ID)));
}
}
if ($query == '' || $query->posts_count() <= 0) {
return;
}
$count = 0;
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$post_title = esc_html(get_the_title($post->ID));
$post_url = esc_url(get_permalink($post->ID));
$url_video = esc_url(get_post_meta($post->ID, THEME_SLUG . 'video_portfolio', true));
$thumb = get_post_thumbnail_id($post->ID);
$thumburl = wp_get_attachment_image_src($thumb, 'blog_thumb');
ob_start();
?>
<div class="portfolio_sc">
<a class="image" href="<?php
echo $post_url;
?>
">
<?php
if ($thumburl[0]) {
?>
<img alt="<?php
echo $post_title;
?>
" title="<?php
echo $post_title;
?>
" class="opacity_0" src="<?php
echo esc_url($thumburl[0]);
?>
"/>
<?php
} else {
?>
<img alt="<?php
echo $post_title;
?>
" title="<?php
echo $post_title;
?>
" class="opacity_0" src="<?php
echo get_template_directory_uri();
?>
/images/no-gallery-830x494.gif"/>
<?php
}
?>
<div class="hover-default"></div>
</a>
<div class="thumb-tag">
<h2 class="post-title heading-title list-title portfolio-grid-title">
<a href="<?php
echo $post_url;
?>
">
<?php
echo $post_title;
?>
</a>
</h2>
</div>
</div>
<?php
}
}
$output = ob_get_contents();
ob_end_clean();
wp_reset_query();
return $output;
}