我想按标签发几封信。所以我尝试使用get\\u posts()函数:
<?php $args = array(
\'numberposts\' => \'3\',
\'post_status\' => \'publish\',
\'tag\' => \'travel\'
);
$recent_posts = get_posts($args);?>
但它不起作用。如何按标签获取帖子?我想按标签发几封信。所以我尝试使用get\\u posts()函数:
<?php $args = array(
\'numberposts\' => \'3\',
\'post_status\' => \'publish\',
\'tag\' => \'travel\'
);
$recent_posts = get_posts($args);?>
但它不起作用。如何按标签获取帖子?请看此部分:Tag parameters 在WP Codex中,其中解释了通过标签进行搜索。
您的代码是正确的。尝试将numberposts更改为int:
<?php $args = array(
\'numberposts\' => 3,
\'post_status\' => \'publish\',
\'tag\' => \'travel\'
);
您可能会发现查看以下链接很有帮助WP Queries 按标记查询。
使用此查询的优点是您可以创建自己的loop, 你可以按你需要的任何安排放置这些帖子。
例如,您可以将文章标题放到列表中,也可以生成标准标题标题,后面跟着摘录或内容。
对于列表,代码如下所示:
<ol>
<?php $args = array(
\'tag\' => \'travel\',
\'posts_per_page\' => 3); ?>
<?php $recent_posts = new WP_Query( $args ); ?>
<?php if ($recent_posts->have_posts()) :
while ($recent_posts->have_posts()) : $recent_posts->the_post();
?>
<li><?php the_title(); ?></li>
<?php endwhile;
else :
echo "Nothing";
endif;
wp_reset_postdata();
?>
</ol>
我在中使用了以下代码functions.php 要翻译一些文本:add_filter(\'gettext\', \'aad_translate_words_array\'); add_filter(\'ngettext\', \'aad_translate_words_array\'); function aad_translate_words_array( $translated ) { $words = array( // \'word to