Skip to content

Instantly share code, notes, and snippets.

@Lysindr
Created September 21, 2016 12:48
Show Gist options
  • Save Lysindr/5e3026fa889e64286ed5e576c43902c9 to your computer and use it in GitHub Desktop.
Save Lysindr/5e3026fa889e64286ed5e576c43902c9 to your computer and use it in GitHub Desktop.
//1 Method - DONT WORK
<?php
$query = new WP_Query(array('category_name' => 'Technology', 'posts_per_page' => 1) ); //указываем имя категории рубрики, которые нужно вывести
if ( have_posts() ) : // если имеются записи в блогею
while ( $query -> have_posts() ) : $query->the_post(); // запускаем цикл перебора материала блога.
?>
<section class="technology-post">
<h5 class="category-name"><?php the_category(); ?></a></h5>
<h1><?php the_title(); ?></h1>
<ul class="post-info">
<li><a href="#"><?php the_author(); ?></a></li>
<li><a href="#"><?php echo get_the_date(); ?></a></li>
<li><a href="#"><?php comments_number('No Comments', '1 Comment', '% Comments'); ?></a></li>
</ul>
</section>
<? endwhile; // завершаем цикл.
endif;
/* Сбрасываем настройки цикла. Если ниже по коду будет идти еще один цикл, что бы не было
сбоя*/
wp_reset_query();
?>
//2 MEthod - WORK
<div class="technology-slider">
<!-- Выведем посты из категории 'Technology' -->
<?php
$slide = array('category_name'=>'Technology', 'posts_per_page'=>-1);
query_posts($slide);
while ( have_posts() ) : the_post();
?>
<div class="slide-container">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/bg-technology.jpg" alt="">
<div class="wrapper">
<section class="technology-post">
<h5 class="category-name"><?php the_category(); ?></a></h5>
<h1><?php the_title(); ?></h1>
<ul class="post-info">
<li><a href="#"><?php the_author(); ?></a></li>
<li><a href="#"><?php echo get_the_date(); ?></a></li>
<li><a href="#"><?php comments_number('No Comments', '1 Comment', '% Comments'); ?></a></li>
</ul>
</section>
</div>
</div>
<? endwhile; // завершаем цикл.
/* Сбрасываем настройки цикла. Если ниже по коду будет идти еще один цикл, что бы не было
сбоя*/
wp_reset_query();
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment