WordPress通过自定义分类显示自定义帖子类型的帖子

时间:2016-04-26 12:53:13

标签: php wordpress twitter-bootstrap post

我有一个自定义帖子类型logie,它有一个自定义分类,现在有3个选项。

我的目标是在不同的引导行中显示每个分类的每个帖子,如下所示:

分类标题1

邮政邮报

分类标题2

邮政邮报

分类标题3

邮政邮报

所以每个Post都是一个col,标题和帖子是连续的

这就是我现在的代码。标题有效,但要获得帖子,这有点棘手。我没有得到任何有点烦人的错误......

<div class="container-full">
        <?php foreach ($cat as $catVal):
              $postArg = array('post_type'=>'logie','posts_per_page'=>-1,'order'=>'desc',
                              'tax_query' => array(
                                                    array(
                                                        'taxonomy' => 'logietype',
                                                        'field' => 'term_id',
                                                        'terms' => $catVal->term_id
                                                    )
                            ));

            $getPost = new wp_query($postArg);
            global $post;
        ?>
            <div class="row">
               <h2><?php echo $catVal->name; ?></h2>
                <?php if($getPost->have_posts()): ?>
                    <?php while ( $getPost->have_posts()):$getPost->the_post(): ?>
                        <div class="col-md-4">
                            <?php echo $post->post_title; ?>
                        </div>
                    <?php endwhile; ?>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </div>

任何人都可以帮助我,非常感谢!!

1 个答案:

答案 0 :(得分:0)

您可以使用更简单的参数查询:

$postArg = array(
  'post_type'=>'logie',
  'posts_per_page'=>-1,
  'order'=>'desc',
  'logietype' => $catVal->term_id
);

顺便说一下,我建议使用更原生的

<?php the_title(); ?>

如果需要可以挂钩。

相关问题