【问题标题】:Wordpress get related pages (tag based) - wp_get_post_tagsWordpress 获取相关页面(基于标签) - wp_get_post_tags
【发布时间】:2014-04-07 11:36:50
【问题描述】:

当我输入 single.php 而不是 page.php 时有效,这是怎么回事?

谁能赐教?

我正在开发 Wordpress 主题,并且想要回显页面的所有标签。

代码:

<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;

$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts'=>5, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '<h3>Related Posts</h3><ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
}
echo '</ul>';
}
}
?>

【问题讨论】:

    标签: wordpress tags


    【解决方案1】:

    在 page.php wp_get_post_tags($post-&gt;ID) 尝试获取页面的标签。 Wordpress 不支持页面标签。要拥有这样的选项,您必须为页面添加标签,使用 plugin 或在众多 tutorials 之一之后添加代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 2011-08-06
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 2023-03-17
      • 2011-12-04
      相关资源
      最近更新 更多