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.135.196.60,归属地:俄亥俄州Dublin ,欢迎您的访问!
文章链接:https://www.ooize.com/wordpress-calls-the-content-list-in-the-same-article-form.html
订阅
提醒
guest

0 评论
内联反馈
查看所有评论
Popup Image

通知

本站原则上是免费提供技术支持,但是服务器维护和运营成本高,可以实行自由赞助:赞助

Loading...