gpt4 book ai didi

wordpress - 只在模板上显示 WordPress 'standard' 帖子格式?

转载 作者:行者123 更新时间:2023-12-02 06:41:14 26 4
gpt4 key购买 nike

我最近在我的 WordPress 主题中添加了帖子格式 - 在博客页面上它很好,因为它们都有相应的样式。然而,在我的主页模板上,我只想显示“标准”帖子格式(没有链接、图库、音频、视频等)。

在我的主题选项中,我可以决定在首页上显示多少帖子,这就是“dft_recent_number”的用途。

有人知道如何更改下面的代码以排除“标准”帖子格式以外的所有格式吗?

<?php 
$query = new WP_Query();
$query->query('posts_per_page='.get_option('dft_recent_number'));

//Get the total amount of posts
$post_count = $query->post_count;

while ($query->have_posts()) : $query->the_post();

?>

非常感谢任何帮助!

最佳答案

WP_Query post_format 似乎没有直接的参数。

根据我的快速研究,帖子格式似乎通过分类法相关。因此,理论上,使用分类参数应该有效。

$args = array(
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-standard',
)
)
);
$query = new WP_Query( $args );

注意:您需要更新博客的分类名称和 slug。这应该是您在 functions.php 文件中设置的名称。

关于wordpress - 只在模板上显示 WordPress 'standard' 帖子格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7486763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com