WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How to add text/ad AFTER More/Excerpt in posts

[Resolved] How to add text/ad AFTER More/Excerpt in posts

  • 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.

    ∞ Verizon CEO says iPhone sales strong, hints at 4G future

    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)
  • keesiemeijer
    Moderator

    @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;
    ?>

    keesiemeijer
    Moderator

    @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;
    ?>

    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;
    ?>
    keesiemeijer
    Moderator

    @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;
    ?>

    brilliant – thanks mate!!!!

    keesiemeijer
    Moderator

    @keesiemeijer

    You’re welcome.

    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

    keesiemeijer
    Moderator

    @keesiemeijer

    Will look in to it

    keesiemeijer
    Moderator

    @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?

    keesiemeijer
    Moderator

    @keesiemeijer

    the same but a little bit smaller:

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

    http://wordpress.pastebin.com/F0gv1YaG

    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

    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’……………

    sorry, that didn’t work!!

    keesiemeijer
    Moderator

    @keesiemeijer

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

    still no ad if no ‘more’

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