我们打开一些用wordpress建站的网站,发现一个问题就是有些文章是广告(随机插入一篇或几篇广告跳转文章),这是怎么实现的呢?在文章中随机插入百度广告,那么如何在文章列表中插入广告呢?下面web建站小编给大家详细介绍一下具体实现代码!
打开主题functions.php
,新增以下代码:
function ads_post_link() { global $post; $thePostID = $post->ID; $post_id = get_post($thePostID); $title = $post_id->post_title; $perm = get_permalink($post_id); $post_keys = array(); $post_val = array(); $post_keys = get_post_custom_keys($thePostID); if (!empty($post_keys)) { foreach ($post_keys as $pkey) { if ($pkey=='url1' || $pkey=='title_url' || $pkey=='url_title') { $post_val = get_post_custom_values($pkey); } } if (empty($post_val)) { $link = $perm; } else { $link = $post_val[0]; } } else { $link = $perm; } echo $link; }
Ps:把主题中输出文章固定链接地址的函数:the_permalink()
替换为我们上面自定义的这个函数:ads_post_link()
!
php语法对index.php首页进行判断(根据需要显示不同页面)
wordpress新建页面中页面属性里没有“模板”选项解决方法
上面是“wordpress如何在文章列表中插入广告”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3519.html
workflows工作流
在地铁站里一个迷茫的非主流姑娘
图生图工作流:粉红色梦幻家园comfyui工作流
一种长着彩虹翅膀的虫子comfyui工作流
令人着迷的一只老虎ComfyUI工作流
一只漂亮的孔雀的尾巴完全由披萨制成ComfyUI工作流
一个超现实和超现实的场景,在森林中心有一座蛇形的房子
三阶放大comfyui工作流
荷塘月色ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!