900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Wordpress在首页列表插入广告位

Wordpress在首页列表插入广告位

时间:2019-05-21 00:50:46

相关推荐

Wordpress在首页列表插入广告位

首先选择首页模板

将代码插入到while循环中

<?php/*** The main template file** This is the most generic template file in 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 /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 --><?phpget_footer();

但是有些问题,下边不会显示

还有写循环的代码

<?php/*** The main template file** This is the most generic template file in 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 /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 --><?phpget_footer();

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。