嘿,伙计们,我有一个问题是,我想要的只是最近发布的标准帖子,只是为了显示,我在主题函数文件中使用了一个函数来显示最近发布的帖子,以及该函数的代码
function aya_last_posts($numberOfPosts = 5 , $thumb = true){
global $post;
$orig_post = $post;
$lastPosts = get_posts(\'numberposts=\'.$numberOfPosts);
foreach($lastPosts as $post): setup_postdata($post);
?>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() && $thumb ) : ?>
<div class="hole-post">
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf( __( \'Permalink to %s\', \'aya\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php aya_thumb(\'aya-medium\'); ?><span class="overlay-icon"></span></a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<div class="tabtitle"><h3><a href="<?php echo get_permalink( $post->ID ) ?>"
title="<?php echo the_title(); ?>"><?php echo the_title(); ?></a></h3></div>
</li>
</div>
<?php endforeach;
$post = $orig_post;
}
我不知道我应该把代码放在哪里,以排除帖子格式,这是一些可以帮助的链接
http://wordpress.mfields.org/2011/post-format-queries/请帮帮伙计们
“我的选项卡”小部件的代码
<?php
## widget_tabs
add_action( \'widgets_init\', \'widget_tabs_box\' );
function widget_tabs_box(){
register_widget( \'widget_tabs\' );
}
class widget_tabs extends WP_Widget {
function widget_tabs() {
$widget_ops = array( \'description\' => \'Most Popular, Recent, Comments, Tags\' );
$this->WP_Widget( \'widget_tabs\',theme_name .\'- Tabbed \', $widget_ops );
}
function widget( $args, $instance ) {
if( empty($instance[\'posts_number\']) || $instance[\'posts_number\'] == \' \' || !is_numeric($instance[\'posts_number\'])) $posts_number = 5;
else $posts_number = $instance[\'posts_number\'];
?>
<div class="widget" id="tabbed-widget">
<div class="widget-container">
<div class="widget-top">
<ul class="tabs posts-taps">
<li class="tabs"><a href="#tab1"><?php _e( \'Popular\' , \'aya\' ) ?></a></li>
<li class="tabs"><a href="#tab2"><?php _e( \'Recent\' , \'aya\' ) ?></a></li>
<li class="tabs"><a href="#tab3"><?php _e( \'Comments\' , \'aya\' ) ?></a></li>
<li class="tabs" style="margin-left:0"><a href="#tab4"><?php _e( \'Tags\' , \'aya\' ) ?></a></li>
</ul>
</div>
<div id="main-warp">
<div id="tab1" class="tabs-wrap">
<ul>
<?php aya_popular_posts( $posts_number ) ?>
</ul>
</div>
<div id="tab2" class="tabs-wrap">
<ul>
<?php aya_last_posts( $posts_number )?>
</ul>
</div>
<div id="tab3" class="tabs-wrap">
<ul>
<?php last_comments( $posts_number );?>
</ul>
</div>
<div id="tab4" class="tabs-wrap tagcloud">
<?php wp_tag_cloud( $args = array(\'largest\' => 8,\'number\' => 25,\'orderby\'=> \'count\', \'order\' => \'DESC\' )); ?>
</div>
</div>
</div>
</div><!-- .widget /-->
5)$实例=wp\\u parse\\u args((数组)$实例,$默认值);?>
<p>
<label for="<?php echo $this->get_field_id( \'posts_number\' ); ?>">Number of items to show : </label>
<input id="<?php echo $this->get_field_id( \'posts_number\' ); ?>" name="<?php echo $this->get_field_name( \'posts_number\' ); ?>" value="<?php echo $instance[\'posts_number\']; ?>" size="3" type="text" />
</p>
<?php
}
}?>
SO网友:Sagive
@用户6394526是对的
您不能真正排除帖子类型,但可以声明要检索的帖子类型。。。请参见他的答案以获取示例。
第二个选项的优先级较低(因为is将查询所有帖子,甚至是您不需要的帖子!)就是检查帖子类型并忽略你不想要的帖子类型。。。
Using your code:
function aya_last_posts($numberOfPosts = 5 , $thumb = true){
global $post;
$orig_post = $post;
$lastPosts = get_posts(\'numberposts=\'.$numberOfPosts);
foreach($lastPosts as $post): setup_postdata($post);
// BUILD POST DATA
$postid = get_the_id();
$postformat = get_post_format($postid)
if($postformat != \'post_format_you_dont_want\') {
?>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() && $thumb ) : ?>
<div class="hole-post">
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf( __( \'Permalink to %s\', \'aya\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php aya_thumb(\'aya-medium\'); ?><span class="overlay-icon"></span></a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<div class="tabtitle"><h3><a href="<?php echo get_permalink( $post->ID ) ?>"
title="<?php echo the_title(); ?>"><?php echo the_title(); ?></a></h3></div>
</li>
</div>
<?php
}
endforeach;
$post = $orig_post;
}
Hope this helps...以下是常见帖子格式列表:
旁白,聊天室除非您创建了一个自定义的库,否则您应该使用您不需要的格式名称,例如:
if($postformat != \'aside\') {