如何在Codeigniter中添加Google Adsense betwen段落

时间:2018-06-20 23:48:47

标签: wordpress codeigniter adsense

我需要您的帮助,请在发布内容(如在wordpress中)之前添加Adsense代码 我显示后弯的代码是这样的

<div class="post-text">
 <?php echo $post->content; ?>
 </div>

3 个答案:

答案 0 :(得分:0)

使用条件如下的循环:如果您想在每7个帖子后展示一次广告,则您的代码就会这样。

    foreach($posts as $key => $post)
    {
       if($key%7 ==0)
       {
        echo 'your adsense code';
       }
    }

答案 1 :(得分:0)

您可以尝试这样的事情:

$str="Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor";

    $str_arr=explode(' ',$str); // use your own delimiter which can be </br> or </p>
    $words_count=count($str_arr);
    $middlecount=($words_count/2);
    $ads_text='Test Demo Test Test Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo Test';
    $str_arr[$middlecount]= $ads_text.'<br>'.$str_arr[$middlecount];

    $final_text=implode(' ',$str_arr);
    echo $final_text;

这是一个测试示例。您的方案需要进行细微调整。

您还可以尝试使用Wordpress的另一种方法,以便用户从管理面板添加内容,然后您要求用户在编辑器的内容中使用预定义的标记(例如ADSENSE)(他要在其中展示广告)

现在在前端,您只需执行以下操作即可:

$post_content=$post->content;
echo str_replace('ADSENSE',$ads_text,$post_content); // will require some tweaks as per requirement 

希望这对您有用

答案 2 :(得分:-1)

$ str =“ Lorem Ipsum测试Dolor Lorem Ipsum测试Dolor Lorem Ipsum测试Dolor Lorem Ipsum测试Dolor Lorem Ipsum测试Dolor Lorem Ipsum测试Dolor Lorem Ipsum测试Dolor Lorem Ipsum测试Dolor Lorem Ipsum测试Dolor Lorem Ipsum Test Dolor Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液测试Dolor Lorem输液Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor Lorem Ipsum Test Dolor“;

$str_arr=explode(' ',$str); // use your own delimiter which can be </br> or </p>
$words_count=count($str_arr);
$middlecount=($words_count/2);
$ads_text='Test Demo Test Test Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo TestTest Demo Test';
$str_arr[$middlecount]= $ads_text.'<br>'.$str_arr[$middlecount];

$final_text=implode(' ',$str_arr);
echo $final_text;