Получить все сообщения определенной категории - Wordpress - PullRequest
0 голосов
/ 13 июня 2018

Я пытаюсь получить все посты категории «Бизнес» и отобразить их в списке шаблонов статей.Тем не менее, запрос возвращает все сообщения всех категорий.

<?php
    $args = array(
        'posts_per_page'   => -1,
        'post_type'        => 'post',
        'category-name'    => 'Business'
    );
    $the_query = new WP_Query( $args );

?>
<?php get_header(  ); ?>
<div class="items-leading">
    <?php while ( $the_query->have_posts() ): $the_query->the_post();?>
<!--Start to display the article-->
<article class="leading-0 item visible-first" id="item-8">
                <!-- Intro image -->
                <figure class="item_img img-intro img-intro__left">
                        <a href="<?php the_permalink(  );?>">
                            <img src="" alt="">
                        </a>
                </figure>

                <!--  title of the article -->
                <header class="item_header">
                <h5 class="item_title heading-style-5 visible-first">
                <a href="<?php the_permalink(  );?>">
                <span class="item_title_part_0 item_title_part_odd item_title_part_first_half item_title_part_first"><?php the_title( );?></span> 
                </a></h5></header>

                <!-- info about the time published and author -->
                <div class="item_info">
                    <dl class="item_info_dl">
                        <dt class="article-info-term"></dt>

                                <dd>
                            <time class="item_published">
                                <?php the_date( );?>    </time>
                        </dd>
                                <dd>
                            <address class="item_createdby">
                            <?php the_modified_author();?>  
                            </address>
                        </dd>
                                <dd>
                            <div class="komento">
                                            </div>
                        </dd>
                            </dl>
                </div>
<!-- Introtext -->
<div class="item_introtext">
    <p>
    <?php echo wp_trim_words( get_the_content(  ), 40, '...')?>
    </p>
</div>

<!-- info BOTTOM -->

<!-- More -->
<a class="btn btn-info" href="<?php the_permalink(  ); ?>">
    <span>
        Read more   
    </span>
</a>
</article>
<div class="clearfix"></div>

<?php endwhile; ?>
</div>
<!-- end items-leading -->
<?php get_footer();?>

Возможно, с кодом что-то не так?Но я не понимаю, так как этот запрос был основан на том, что я нашел в Интернете.Буду признателен за помощь.

Ответы [ 3 ]

0 голосов
/ 13 июня 2018

Никаких проблем с запросом нет, просто простая глупая ошибка.

<?php get_header(  ); ?>

будет в начале файла, а затем разместите свой запрос arg & all.

0 голосов
/ 13 июня 2018

Хм ... Я не уверен, но каким-то образом я изменил запрос, и он работает хорошо ._.?

Так волшебно.

<?php get_header(  ); ?>
<?php
    $args = array(
        'posts_per_page'   => -1,
        'post_type'        => 'post',
        'cat'      => '8'
      );
    $the_query = new WP_Query( $args );

?>
0 голосов
/ 13 июня 2018

Я думаю, что есть проблема с $ args, попробуйте с этим:

$args = array(
  'posts_per_page'   => -1,
  'post_type'        => 'post',
  'category_name'    => 'Business'
);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...