logo

$30
Add a sponsor block after more tag in single.php

I am looking to add a sponsor block after the more tag in the single.php.

I want it to be site wide - I don't want to put something in every post - I want to change it via theme - it will most likely be a buysellads.com placement.

Is this even possible?

you can view the theme I am working on http://lab.inspiredology.com/typography-post/

You will see the sponsor block - I want to move that down, so it sits after the first paragraph or two.

Here is the basic code for the area...


<div class="post_ad">
<a href="#">
<img src="http://envato.s3.amazonaws.com/referrer_adverts/gr_468x60_v4.gif" alt="Post Ad" width="468" height="60" align="middle" class="ad_468"/>
</a>
</div>

<div class="entry-content">

<div class="entry-image">
<?php the_content() ?>
</div>
</div>

attachment image View Attachment

Chad Mueller | 07/03/10 at 8:30am | Edit


(5) Possible Answers Submitted...

  • avatar
    Last edited:
    07/03/10
    8:38am
    Darrin Boutote says:

    Do you want it actually in the post? Or after the post?

    • 07/03/10 8:56am

      Chad Mueller says:

      I want it in the post - not before or after - within the post

  • avatar
    Last edited:
    07/03/10
    8:55am
    Matt K says:

    Hi Chad,

    I think putting the ad code after

    <?php the_content() ?>
    should do it, unless it's more complicated than that?

    • 07/03/10 8:56am

      Chad Mueller says:

      no it's more complicated then that - that would just put it after the content - which i don't want...

  • avatar
    Last edited:
    07/03/10
    9:17am
    Utkarsh Kukreti says:

    add_filter('the_content', 'insert_ads_in_content');

    function insert_ads_in_content($content)
    {
    if(!is_single()) return $content;
    $ad = <<<EOT
    <div class="ad">
    <!-- ad content -->
    </div>
    EOT;
    $after = 2; // after which paragraph?

    $ps = explode('</p>', $content);
    $o = '';
    for($i = 0; $i < count($ps); $i++)
    {
    if($after == $i) $o .= $ad;
    $o .= $ps[$i] . '</p>';
    }
    return $o;
    }

    Previous versions of this answer: 07/03/10 at 9:09am

    • 07/03/10 9:07am

      Chad Mueller says:

      Utkarsh - that works great - one concern

      It shows up on every page - I just want to show up in single.php

    • 07/03/10 9:10am

      Utkarsh Kukreti says:

      Edited.

  • avatar
    Last edited:
    07/03/10
    9:02am
    Oleg Butuzov says:

    Hi Chad. try this. (insert it to the functions.php of your theme)

    add_filter('the_content', 'adds_block');

    function adds_block($content){

    if (!is_single()) return $content;

    return str_replace('<!--more-->', ads(), $content);

    }

    function ads(){
    return 'banner code';
    }

    Previous versions of this answer: 07/03/10 at 9:02am

  • avatar
    Last edited:
    07/03/10
    9:17am
    Monster Coder says:

    Write these codes in the functions.php in theme directory:

    $sponsor_texts = 'THIS IS SPONSORED TEXT';
    if(is_single()){
    add_filter('the_content','sponsors_link');
    }
    function sponsors_link($content){
    global $sponsor_texts;
    return str_replace(array('<span id="more-'.get_the_ID().'"></span>','<!--more-->'),array($sponsor_texts,$sponsor_texts),$content);
    }


    Change $sponsor_texts variable to put your sponsor codes

    Previous versions of this answer: 07/03/10 at 9:10am | 07/03/10 at 9:17am

    • 07/03/10 9:13am

      Monster Coder says:

      The code of Utkarsh Kukreti seems fine! But it will always add sponsor after 2nd paragraph, not after more tag! more tag may not be always after 2nd paragraph!

      Note: I have tested my code with Twenty Ten theme! On other theme, need to check what <!--more--> is replaced with! we need to search and replace that only!

    • 07/03/10 9:22am

      Chad Mueller says:

      I put this in - but I was unable to see any results.....

      I understand what you are saying - it would be more dynamic if it went after the more tag - but after the first paragraph is ok as well - so it doesn't cut any content in half -

This question has expired.





Current status of this question: Completed