【问题标题】:Wordpress - Turn Pages into Posts and display Child of all Parents, whilst removing the Parent.Wordpress - 将页面变成帖子并显示所有父母的孩子,同时删除父母。
【发布时间】:2012-08-29 16:59:51
【问题描述】:

我有什么:

  • 首页
  • 关于
    • 项目
      • 项目页面 1
        • 项目 1
      • 项目页面 2
        • 项目 2
      • 项目页面 3
        • 项目 3

我想循环浏览项目子页面,以便按所有子项目中最近的顺序显示页面,然后能够回显或拉出自定义字段,

<?php the_title();?> 
<?php the_excerpt();?>

但我不想实际显示父页面,例如项目 1 或项目 2 或项目 3 等。

尝试了很多事情,但似乎无法使用 array_merge 或 wp_list_pages 来做到这一点。

任何帮助都会阻止我拔头发。非常感激。

【问题讨论】:

    标签: php loops wordpress-theming wordpress


    【解决方案1】:

    阅读下面的网址,我相信它对您很有帮助。

    如何在 WordPress 类别页面上从子类别中排除帖子

    http://thesistut.com/2012/exclude-posts-from-children-category/

    【讨论】:

      【解决方案2】:

      我找到了方法。我使用了以下代码。我希望它可以帮助某人。

      <?php
      $args=array(
      'post_type' => 'page',
      'post__in' => array(345, 289),
      'post_status' => 'publish',
      'posts_per_page' => 2,
      'caller_get_posts'=> 1
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      
      if( $my_query->have_posts() ) {
      
      while ($my_query->have_posts()) : $my_query->the_post();
      
      ?>
      

      这产生了 2 个作为页面的帖子,来自特定类别而不显示父级,避免使用 wp_list,而是使用 new WP_Query$args。它作为临时修复工作,但确实有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-13
        • 2021-08-08
        • 1970-01-01
        相关资源
        最近更新 更多