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 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 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 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();
Wordpress在首页列表插入广告位相关推荐
- 如何对phpcms v9的首页列表进行分页?
如何对phpcms v9的首页数据列表进行分页?我在phpcms论坛上看到很多相关的帖子提到,但都没有解决这个问题.提出这个问题的人,是想把phpcms v9做成博客的样子,但是不是有很多优秀的博客程 ...
- wordpress网站首页模板主题开发制作
本篇文章为大家带来的是wordpress网站首页模板主题开发制作教程,首页是做为网站开发最重要的页面之一,也是必不可少的一个页面,首页所包含的内容相对来说也是网站所有页面里面包含内容最多的一个页面,其 ...
- 宽屏首页列表翻页教程网(带手机) v5.26
介绍 宽屏首页列表翻页教程网源码是asp+access/mssql架构网站系统,电脑版,手机版,平板版无缝切换,一个后台同步管理,整站生成静态利于搜索收录,dreamweaver打开可视化修改. 可用 ...
- python list的extend (会将被插入的列表的每个元素从列表中拿出添加到列表中)与append方法(若被插入为列表,会将列表插入到源列表中)区别
python list的extend (会将被插入的列表的每个元素从列表中拿出添加到列表中)与append方法(若被插入为列表,会将列表插入到源列表中)区别 Python--list的extend() ...
- Asp.net MVC 仿照博客园的简单网站首页 列表设计
本来我打算采用ajax提交请求,异步的请求获取数据,但是我发现如果这样的话就会拖慢开发的进度,拖长时间.所以在这篇博客中仿照首页的列表设计其实和左侧列表网站分类采用了同样的方式,通过局部视图的方式呈现 ...
- 链接列表插入删除方法
链接列表插入方法 (Linked List Insert Methods) Linked List Insert 链表插入 Linked List insert methods allow us to ...
- 【python列表插入函数】append() extend() insert() 三者区别与使用方法
三个列表插入函数 append() extend() insert() append() append()函数是在列表末尾添加元素 append()括号内可以是数字.字符串- a=[1,2] a.ap ...
- word首页之前插入空白页没有页眉页脚且不影响后续页码
问题1:如何在首页之前插入不含页眉页脚的空白页 方法:1.光标定位在待插入页面首端,依次点击 页面布局--分隔符--连续,生成了一张带有页眉页脚的页面(若之前页面有页眉页脚) 2.继续对待插入页面操作 ...
- 【收藏】清风算法后网站首页/列表页/内容页/主题聚合页标题格式
清风算法后网站首页/列表页/内容页/主题聚合页标题格式: 首页: 标题格式:"站点名/品牌名_首页/官网/slogan" 列表/频道页 标题格式:"列表/频道名_上级频道 ...
最新文章
- Eclipse开发struts完全指南
- 微软或允许 Android 应用运行于 Windows 和 WP
- new Scanner(1.txt);读取不到文件中的数据
- layui 隐藏工具栏打印按钮_PDF如何打印?为什么点打印没反应?
- html层次选择器例题,JQuery 层次选择器的例子
- php 写一个大富翁游戏,C++大富翁代码 现在要设计一个类似“大富翁”的游戏:有一条由20个格子组成的 联合开发网 - pudn.com...
- calibre for linux,calibre - 
下载Linux版
- python代码加密cython_python通过cython实现加密
- 主题:spring集成quartz,出现2次重复调用的问题
- 7450清零_兄弟MFC-7450打印机硒鼓加粉 兄弟MFC-7450打印机怎么清零【图文】
- 你画我猜---websocket
- ThreadLocal工具类
- 1.(MySQL Router+MGR)MySQL Shell安装与用法
- 谭谭牛顿的牛眼之人眼是红外线成像仪谭
- wps怎么减少行间距_wps怎么设置行距_wps的行间距在哪怎么调整单倍行距及1.5倍行距_wps文字_office之家...
- vue 中父子组件传递通信(看图就会了,皮卡皮卡)
- python字体加粗代码_如何在python docx中加粗行单元格的文本?
- 历届图灵奖和马尔奖获得者
- PacBio三代宏基因组测序大幅提升海洋水体宏基因组研究效果
- 12.5 比较判别法极限形式
热门文章
- OpenCV中的saturate操作(饱和操作)究竟是怎么回事?
- LINUX终端登录时提示 Login incorrect
- 2021年最新Spring面试题,常见面试题及答案汇总
- 培养管理意识,增强执行力
- GO连接数据库--踩坑(超详细)
- restkeeper
- python pyh html解决中文中文乱码的方法
- 1,2-二苯基-1,2-二(4-苄溴基苯基)乙烯;TPE-MB结构式
- java isempty用法_Java List isEmpty()用法及代码示例
- Halcon双目结构光定位(2)-三维模板匹配及按照点云高度排序