• Resolved Everton

    (@everton)


    Hi

    I want to add some text or an ad after the ‘more’ tag or after a custom excerpt i.e.

    – More text first

    – image/custom text or ad

    – then rest of post

    Loopinsight.com has managed this on their posts e.g.

    https://www.loopinsight.com/2011/02/25/verizon-ceo-says-iphone-sales-strong/

    An ad is displayed after the more/excerpt:

    Verizon Wireless CEO Daniel S. Mead told The Wall Street Journal that sales of the iPhone 4 were very strong, contrary to reports that the phone wasn’t selling as well as expected. The article, penned by Shayndi Raice, included some other tasty tidbits too (it’s behind a paywall).”

    an ad, and then the rest of the post.

    Thanks in advance for any help

Viewing 15 replies - 1 through 15 (of 19 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    On your theme’s single.php use this in stead of <?php the_content(); ?>:

    <?php
    $content = get_extended($post->post_content);
    $first_content = apply_filters('the_content', $content['main']);
    $second_content = apply_filters('the_content', $content['extended']);
    
    echo $first_content;
    // put the code for your ads here
    echo $second_content;
    ?>

    Moderator keesiemeijer

    (@keesiemeijer)

    This is even better:

    <?php
    $content = get_extended($post->post_content);
    $content['main'] = $content['main'] . '<span id="more-' . $post->ID . '"></span>';
    $first_content = apply_filters('the_content', $content['main']);
    $second_content = apply_filters('the_content', $content['extended']);
    
    echo $first_content;
    
    // put the code for image/custom text or ad here
    
    echo $second_content;
    ?>
    Thread Starter Everton

    (@everton)

    thanks for the fast reply. This is probably a very daft question, but I can’t get my ad to display without an error. The code I want to put after the excerpt isn’t working – what am I doing wrong?

    Thanks

    <?php
    $content = get_extended($post->post_content);
    $content['main'] = $content['main'] . '<span id="more-' . $post->ID . '"></span>';
    $first_content = apply_filters('the_content', $content['main']);
    $second_content = apply_filters('the_content', $content['extended']);
    
    echo $first_content;
    
    <div style="display:block;float:left;margin-top:0px;margin-right:15px;">
    <script type="text/javascript">
      GA_googleFillSlot("CI_Article_Top");
    </script>
    </div>
    
    echo $second_content;
    ?>
    Moderator keesiemeijer

    (@keesiemeijer)

    Not daft at all. try it with this:

    <?php
    $content = get_extended($post->post_content);
    $content['main'] = $content['main'] . '<span id="more-' . $post->ID . '"></span>';
    $first_content = apply_filters('the_content', $content['main']);
    $second_content = apply_filters('the_content', $content['extended']);
    
    echo $first_content;
    ?>
    
    <div style="display:block;float:left;margin-top:0px;margin-right:15px;">
    <script type="text/javascript">
      GA_googleFillSlot("CI_Article_Top");
    </script>
    </div>
    
    <?php
    echo $second_content;
    ?>

    Thread Starter Everton

    (@everton)

    brilliant – thanks mate!!!!

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome.

    Thread Starter Everton

    (@everton)

    actually, just spotted one big problem. If there isn’t an excerpt or if a post doesn’t have a ‘more’ added, then my ad isn’t displayed at all.

    How do we modify the code so that if there’s a more it does what we have above, but if there isn’t, then it displays my ad before the full post?

    Thanks

    Moderator keesiemeijer

    (@keesiemeijer)

    Will look in to it

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    [code moderated as per forum rules - please use the pastbin for these large amounts of code]

    This will just show the_content() if there is no "more" in the post. What do you mean if there is no excerpt?

    Moderator keesiemeijer

    (@keesiemeijer)

    the same but a little bit smaller:

    [code moderated as per forum rules - please use the pastbin for these large amounts of code]

    https://wordpress.pastebin.com/F0gv1YaG

    Thread Starter Everton

    (@everton)

    it doesn’t quite work – what I want it do to is show the ad and then the_content() if there’s no ‘more’ – it’s currently showing just the_content().

    Really appreciate you trying to help

    Thread Starter Everton

    (@everton)

    fixed it….
    ……..
    <?php
    $content = get_extended($post->post_content);
    if(empty($content)) : ?>
    <?php the_content(); ?>
    <?php else : ?>
    <div style=”display:block;float:left;margin-top:0px;margin-right:15px;”>
    <script type=”text/javascript”>
    GA_googleFillSlot(“CI_Article_Top”);
    </script>
    </div><?php
    $content[‘main’……………

    Thread Starter Everton

    (@everton)

    sorry, that didn’t work!!

    Moderator keesiemeijer

    (@keesiemeijer)

    Oops didn’t know my code was getting to big.
    try with this: https://wordpress.pastebin.com/1WMceQS4

    Thread Starter Everton

    (@everton)

    still no ad if no ‘more’

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘How to add text/ad AFTER More/Excerpt in posts’ is closed to new replies.