【问题标题】:wordpress - other posts of the same category on post pagewordpress - 帖子页面上相同类别的其他帖子
【发布时间】:2011-03-28 15:12:12
【问题描述】:

我需要在wordpress中的帖子内容之后链接同一类别的最后5个帖子。任何人都可以帮助我吗?谢谢

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    在循环之前声明一些将保存帖子类别的变量。比用那只猫查询帖子。

    示例如下:

    <?php
    $cat_id = 0; // declare var
    if(have_posts()):
      while(have_posts()):
        // do what you usually do
        $cat_id = $post->post_category;
      endwhile;
    endif;
    
    // here you will get posts and make html output
    $last_in_cat = get_posts('posts_per_page=5&cat='.$cat_id);
    foreach($last_in_cat as $cat_post):
    ?>
    <a href="<?php $cat_post->guid ?>"><?php $cat_post->post_title ?></a>
    <?php endforeach; ?>
    

    【讨论】:

      【解决方案2】:

      您可以使用WP_Query 获得您想要的任何东西。它非常灵活,您绝对应该开始使用它。 就像 SQL 查询一样。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多