WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add text/ad AFTER More/Excerpt in posts (20 posts)

  1. Everton
    Member
    Posted 3 years ago #

    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.

    http://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

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    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;
    ?>
  3. keesiemeijer
    moderator
    Posted 3 years ago #

    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;
    ?>
  4. Everton
    Member
    Posted 3 years ago #

    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;
    ?>
  5. keesiemeijer
    moderator
    Posted 3 years ago #

    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;
    ?>
  6. Everton
    Member
    Posted 3 years ago #

    brilliant - thanks mate!!!!

  7. keesiemeijer
    moderator
    Posted 3 years ago #

    You're welcome.

  8. Everton
    Member
    Posted 3 years ago #

    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

  9. keesiemeijer
    moderator
    Posted 3 years ago #

    Will look in to it

  10. keesiemeijer
    moderator
    Posted 3 years ago #

    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?

  11. keesiemeijer
    moderator
    Posted 3 years ago #

    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

  12. Everton
    Member
    Posted 3 years ago #

    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

  13. Everton
    Member
    Posted 3 years ago #

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

  14. Everton
    Member
    Posted 3 years ago #

    sorry, that didn't work!!

  15. keesiemeijer
    moderator
    Posted 3 years ago #

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

  16. Everton
    Member
    Posted 3 years ago #

    still no ad if no 'more'

  17. Everton
    Member
    Posted 3 years ago #

    the ad goes below the_content(), rather than before

  18. keesiemeijer
    moderator
    Posted 3 years ago #

  19. Everton
    Member
    Posted 3 years ago #

    thanks that worked.

  20. Chukwudi Emmanuel Udegbunam
    Member
    Posted 3 years ago #

    This one worked for me guys. Thanks a lot ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic