
我们打开一些用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如何在文章列表中插入广告”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3519.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

Win7系统禁用虚拟键盘教程
一款互动式小说AI生成工具——MidReal