我想通过在帖子中间插入广告代码functions.php
.
我找到了几个链接,但它们要么不使用functions.php
或者不要在中间在中间。
谁能告诉我怎么做?
另外,我不想使用插件。
我想通过在帖子中间插入广告代码functions.php
.
我找到了几个链接,但它们要么不使用functions.php
或者不要在中间在中间。
谁能告诉我怎么做?
另外,我不想使用插件。
此函数用于在指定段落后插入广告代码。
add_filter(\'the_content\', \'wpse_ad_content\');
function wpse_ad_content($content)
{
if (!is_single()) return $content;
$paragraphAfter = 2; //Enter number of paragraphs to display ad after.
$content = explode("</p>", $content);
$new_content = \'\';
for ($i = 0; $i < count($content); $i++) {
if ($i == $paragraphAfter) {
$new_content.= \'<div style="width: 300px; height: 250px; padding: 6px 6px 6px 0; float: left; margin-left: 0; margin-right: 18px;">\';
$new_content.= \'//Enter your ad code here....\';
$new_content.= \'</div>\';
}
$new_content.= $content[$i] . "</p>";
}
return $new_content;
}
有几种备选方案:
首先,您可以按照@iambriansreed的建议使用短代码,但您需要了解PHP编程才能注册短代码。以下代码为from a website (in spanish) 这显示了如何使用Adsense编写一个简单的短代码:
/*
* Copy the code into your theme\'s functions.php file
* Change the AdSense <script> for yours
*/
function showads() {
return \'<div><script type="text/javascript"><!--
google_ad_client = "pub-XXXXXXXXXXXXXX";
google_ad_slot = "4668915978";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>\';
}
add_shortcode(\'adsense\', \'showads\');
其次,您可以使用如下插件Quick Adsense 实现相同的短代码,但很容易自定义,或者让插件选择放置广告的位置。最后,您可以编写自己的代码在第n段添加广告(即利用每个段落并选择第n段,然后在那里添加您的广告代码)。这不是最好的解决方案,但可以完全定制。
所以很明显,如何从模板中排除某些类别,但我不想修改4个模板,使它们忽略某个类别。有没有一种方法可以将某个类别从阅读设置的“博客”集中排除?我正在将博客分配到名为“博客”的页面。。。但显然,档案和搜索也需要对这一超出类别的内容视而不见。我宁愿在里面做functions.php