Code lặp sau 5 bài viết, hiển thị 1 quảng cáo trong catalogy WordPress

Đánh giá post
Hướng dẫn Code lặp sau 5 bài hiển thị 1 quảng cáo trong catalogy WordPress

Thay thế đoạn code bên dưới vào File archive.php trong theme

<div class='labelall-thaiaiti'>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php $index  = 0; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content', get_post_format() );
$index++;
if ($index == 5) {
$index  = 0;
?>
<div class="ads">
ads
</div>
<?php
}
?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div>
Đánh giá post


Trả lời