dongqiaochi2711 2010-11-17 14:25
浏览 45
已采纳

Wordpress显示今天按类别组织的帖子

I need to create a "Today's Daily News" page for an internal company 'newspaper'. It is run on a wordpress, so the not-so-savvy can handle it. The page just needs to display a tree-ish view of the categories with ONLY TODAY's posts listed in them. If there are no news items in any of the categories for today, then they should not be displayed. I have found some useful bits of code which I can patch together to achieve this, but really I want to utilize as much of wordpress' built in functions as possible. This is the format I am looking for:

Today's Daily News

-Category 1

---News Item Title 1A

---News Item Title 1B

---News Item Title 1C

---News Item Title 1D


-Category 2

---News Item Title 2A

---News Item Title 2B
  • 写回答

2条回答 默认 最新

  • dongniechi7825 2010-11-17 19:36
    关注

    After some research, I figured out how to get this to work. I create a page template called "Today's Post" and you can see the source below:

    <?php
    /*
    Template Name: Today's Posts
    */
    ?>
    <?php get_header(); ?>
    <ul>
    <?php
    $today = getdate();
    $categories = get_categories("orderby=name&parent=0");
    foreach ($categories as $category) {
        query_posts('year='.$today["year"].'&monthnum='.$today["mon"].'&day='.$today["mday"].'&post_type=post&post_status=publish&cat='.$category->term_id);
        echo "  <li>
    "
            ."    <a href=\"".get_category_link($category->term_id)."\">".$category->name."</a>
    "
            ."    <ul>
    ";
        while (have_posts()) : the_post();
    ?>
          <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php
        endwhile;
        echo "    </ul>
    "
            ."  </li>
    ";
    }
    ?>
    </ul>
    <?php get_footer(); ?>
    

    To show child categories, remove "&parent=0" and likewise change it to a category ID if you just want to display that categories children.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退