Wordpress:订购自定义帖子类型

时间:2016-05-30 01:22:22

标签: php wordpress

$args = array(
  'labels'        => $labels,
  'description'   => 'Add new Home Subnav',
  'public'        => true,
  'menu_position' => 25,
  'hierarchical'  => true,
  'supports'      => array('title', 'thumbnail', 'editor', 'page-attributes'),
  'has_archive'   => false,
);

我在Wordpress中创建了上面的自定义帖子类型支持,我想通过order属性来命令帖子。 (1 - 6)。下面是我定义的当前WP_Query:

    $subnavArgs = array(
      'post_type' => 'home_subnav',
      'posts_per_page' => 6,
      'orderby' => 'menu_order',
      'order' => 'ASC'
    );

    $subnav = new WP_Query( $subnavArgs );

我已经看了很多,但解决方案似乎都没有用。我不确定是否需要添加更多支持,或者我的WP_Query参数是否有问题。

完整循环代码

<?php
    $subnavArgs = array(
      'posts_per_page'  => 6,
      'orderby'         => 'menu_order',
      'order'           => 'ASC',
      'post_type'       => 'home_subnav'
    );

    $subnav = new WP_Query( $subnavArgs );
    if ($subnav->have_posts()) : while ($subnav->have_posts()) : $subnav->the_post();
  ?>

  <div class="col-sm-2 col-xs-4 cta-box">
    <?php the_post_thumbnail(); ?>
    <h2><?php the_title(); ?></h2>
    <div class="menu-content">
      <?php
        echo get_the_content();
      ?>
    </div>
  </div>

  <?php
    endwhile; endif; wp_reset_postdata();
  ?>

0 个答案:

没有答案