wordpress调用相同文章形式的内容列表
文章目录
大挖的wordpress导航主题,集成了两种文章形式,默认形式即导航形式,还有一个日志形式,就是我们传统说的资讯形式,在使用相关文章和资讯列表调用时,大挖使用的相关的wordpress文章形式调用,这样可以避免出样在不同的列表里出来导航列表内容又出现资讯文章内容。
现在把代码分享给大家,需要提示给大家的是此段代码里的post-format-image是主要的核心要素,格式是这样的post-format-{name},name是指文章形式的名称,可以用的有:aside、image、video、quote、link、gallery、status、audio、chat等wordpress默认的文章形式。
<?php $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 the_permalink(); ?>" target="_blank" title="<?php the_title();?>"><?php the_title();?></a></li> <?php wp_reset_postdata(); endforeach; endif; ?>
内容页面调用相同文章形式的文章列表
<?php
$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 the_permalink(); ?>" target="_blank" title="<?php the_title();?>"><?php the_title();?></a></li>
<?php
wp_reset_postdata();
endforeach;
endif;
?>
©️李联华的博客网 当前IP地址:3.144.7.118,归属地:俄亥俄州Dublin ,欢迎您的访问!
温馨提示 : 非特殊注明,否则均为李联华的博客原创文章,本站文章未经授权禁止任何形式转载
文章链接:https://www.ooize.com/wordpress-calls-the-content-list-in-the-same-article-form.html
文章链接:https://www.ooize.com/wordpress-calls-the-content-list-in-the-same-article-form.html
订阅
登录
0 评论