0

我想根据帖子的类别显示一些内容。我的意思是,如果有人阅读“旅行”类别中的帖子,我想在“游戏”类别中显示一些与此相关的提示,以及其他一些内容。我最好在侧边栏中需要这个。有没有插件?如果没有,是否可以通过一些修改来实现

4

2 回答 2

0

尝试这个:

<?php

        $args2 = array(
            'numberposts' => 1,
            'cat' => 4,
            'orderby' => 'date',
            'order' => 'DESC',
            'post_type' => 'post',
            'post_parent' => '',
            'post_status' => 'publish',
            'suppress_filters' => true
        );
        $homepage_content = get_posts($args2);

        foreach ($homepage_content as $key => $value) {
            echo "<h2>" . $value->post_title . "</h2>";
            echo $value->post_content;
            $post_id = $value->ID;
        }

?>

这里只需在 cat 参数中传递 Category 的 ID。

For more reference: http://codex.wordpress.org/Template_Tags/get_posts 

- 谢谢

于 2013-10-23T12:40:29.320 回答
0

试试这个代码:

只需将“CATEGORYNAME”替换为您想要的类别名称即可:

<?php query_posts('category_name=CATEGORYNAME&showposts=5');
while (have_posts()) : the_post();
  // do whatever you want
?>
<b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
?>
于 2013-10-23T12:12:40.273 回答