gpt4 book ai didi

php - 在 WordPress 中显示搜索词(标签/存档)

转载 作者:行者123 更新时间:2023-11-28 03:11:26 25 4
gpt4 key购买 nike

我目前在 WordPress 中使用侧边栏,并在侧栏中显示“存档”和“热门标签”。

例如 - 存档代码

  <div class="populartags">
<?php
$tags = get_tags();
$html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
$tag_link = get_tag_link( $tag->term_id );

$html .= "<a style='color:#333;' href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
$html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;
?>
</div>

这会显示已在帖子中使用的所有标签。我也有存档(日期)-

<?php wp_get_archives(); ?>

这些页面,转到archive.php,太棒了。我正在努力实现的目标。是一行文本,上面写着

'这是(存档/标签)的帖子。'

所以,如果我查看 2015 年 5 月的帖子。它会说“这是 2015 年 5 月的帖子”

有人有什么想法吗?

最佳答案

你需要编辑archive.php

只需添加

<?php if( is_month() ) { ?> // Check if month based archive
<?php echo 'Here are the posts for'; ?>
<?php the_time('F Y');
} ?>

关于php - 在 WordPress 中显示搜索词(标签/存档),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30356122/

25 4 0