M
M
Maxim2015-08-15 23:49:56
CMS
Maxim, 2015-08-15 23:49:56

Showing a page and a post in a Wordpress category?

Good afternoon!
Tell me how you can display the post page in the Wordpress heading:
I explain the page (page.php), heading (archive.php), posts (single.php). A small nuance of the entry must be of a certain category.
Tried with :

<?php
if ( have_posts() ) : // если имеются записи в блоге.
query_posts( array( 'taxonomies' => 'remont-kompyuterov-v-kazani' ) );  // указываем ID рубрик, которые необходимо вывести.
while (have_posts()) : the_post();  // запускаем цикл обхода материалов блога
get_template_part( 'content', get_post_format() );
  endwhile;  // завершаем цикл.
endif;
?>

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
webpixel, 2015-08-17
@webpixel

all info here: https://codex.wordpress.org/Class_Reference/WP_Query
here is an example:

<?php 
// the query
$the_query = new WP_Query( 'category_name=YOUR_CATEGORY' ); ?>

<?php if ( $the_query->have_posts() ) : ?>

  <!-- pagination here -->

  <!-- the loop -->
  <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>
  <?php endwhile; ?>
  <!-- end of the loop -->

  <!-- pagination here -->

  <?php wp_reset_postdata(); ?>

<?php else : ?>
  <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question