wordpress调用相同文章形式的日志列表

调用指定文章形式的日志列表:

全站可用

<?php 
//by 博客吧
	$posts = get_posts(array(
		'numberposts' => '10',
		'post_type' => 'post',		
		'tax_query'=>array(
			array(
				'taxonomy'=>'post_format',
				'field' => 'slug',
				'terms' => array('post-format-image')
			)
		),
	)
	);	
	if($posts):	
		foreach($posts as $post):
?>
<li><a href="<?php%20the_permalink();%20?>" target="_blank" title="<?php the_title();?>"><?php the_title();?></a></li>
<?php 
		wp_reset_postdata(); 
		endforeach; 
	endif; 
?>

代码中的post-format-image是要调用的文章列表,格式是post-format-{name},name是文章形式的名称,如:aside、image、video、quote、link、gallery、status、audio、chat。

内容页面调用相同文章形式的文章列表

仅限文章页面,可以当相关文章使用

<?php 
//by 博客吧
	$posts = get_posts(array(
		'numberposts' => '10',
		'post_type' => 'post',
		'exclude'=>get_the_ID(),
		'tax_query'=>array(
			array(
				'taxonomy'=>'post_format',
				'field' => 'slug',
				'terms' => array('post-format-image'.get_post_format())
			)
		),
	)
	);	
	if($posts):	
		foreach($posts as $post):
?>
<li><a href="<?php%20the_permalink();%20?>" target="_blank" title="<?php the_title();?>"><?php the_title();?></a></li>
<?php 
		wp_reset_postdata(); 
		endforeach; 
	endif; 
?>

分享到: 生成海报
avatar

热门文章

  • 一对一资讯网 为您提供可靠的服务

    一对一主机系统飞蝌云计算
    登录一对一资讯平台  

    登录

    忘记密码 ?