<?php
/**
* The main template file
*
* This is the most generic template filein a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
get_header();
?><section id="primary"class="content-area"><main id="main"class="site-main"><?php if( have_posts()): ?><?php // Load posts loop.?><?php while( have_posts()): the_post();?><?php if( wp_is_mobile()): ?><?php get_template_part('template-parts/content/content', 'mobile'); ?><?php else: ?><?php get_template_part('template-parts/content/content'); ?><?php endif; ?><?php if($wp_query->current_post ==3): ?><div> 广告代码 </div><?php endif; ?><?php if($wp_query->found_posts <4 and $wp_query->current_post ==($wp_query->found_posts - 1)): ?><div> 广告代码 </div><?php endif; ?><?php if($wp_query->current_post ==7): ?><div> 广告代码 </div><?php endif; ?><?php if($wp_query->found_posts <8 and $wp_query->current_post ==($wp_query->found_posts - 1)): ?><div> 广告代码 </div><?php endif; ?><?php endwhile; ?><?php // Previous/next page navigation.?><?php twentynineteen_the_posts_navigation(); ?><?php if($wp_query->current_post ==11): ?><div> 广告代码 </div><?php endif; ?><?php if($wp_query->found_posts <12 and $wp_query->current_post ==($wp_query->found_posts - 1)): ?><div> 广告代码 </div><?php endif; ?><?php else: ?><?php // If no content, include the "No posts found" template. ?><?php get_template_part('template-parts/content/content', 'none');?><?php endif; ?></main><!-- .site-main --></section><!-- .content-area --><?php
get_footer();
但是有些问题,下边不会显示
还有写循环的代码
<?php
/**
* The main template file
*
* This is the most generic template filein a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
get_header();
?><section id="primary"class="content-area"><main id="main"class="site-main"><?php if( have_posts()): ?><?php // Load posts loop.?><?php while( have_posts()): the_post();?><?php if( wp_is_mobile()): ?><?php get_template_part('template-parts/content/content', 'mobile'); ?><?php else: ?><?php get_template_part('template-parts/content/content'); ?><?php endif; ?><?php for($i=4;$i<=$wp_query->found_posts;$i=$i+4) :?><?php if($wp_query->current_post ==$i-1): ?><div>
广告代码
</div><?php endif; ?><?php if($wp_query->found_posts <1000 and $wp_query->current_post ==($wp_query->found_posts - 1)): ?><div>广告代码</div><?php endif; ?><?php endfor; ?><?php endwhile; ?><?php // Previous/next page navigation.?><?php twentynineteen_the_posts_navigation(); ?><?php else: ?><?php // If no content, include the "No posts found" template. ?><?php get_template_part('template-parts/content/content', 'none');?><?php endif; ?></main><!-- .site-main --></section><!-- .content-area --><?php
get_footer();