• I’m looking for a way to insert something immediately following the more tag, i.e., after the jump. I have some custom single.php files tied to specific categories, and the inserted content would need to vary for each one.

    Any suggestions?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Rich Owings

    (@gpsmapper)

    I’m aware that the Sniplets plugin will do this, but its not working on my main site.

    this snippet uses the <span id="more to break the content in two parts, and to do ‘something’ inbetween (used in single.php).
    without ‘more’ tag, the whole content shown, no ‘something’ is done.

    <?php  $story = get_the_content();
    $story = explode('<span id="more',$story);
    $first_part_of_story = $story[0];
    $second_part_of_story = $story[1];
    $first_part_of_story = apply_filters('the_content', $first_part_of_story);
    echo $first_part_of_story;
    if ($second_part_of_story) {
    // here 'something' code // ;
     } ;
    $second_part_of_story = explode('</span>',$second_part_of_story);
    $second_part_of_story = apply_filters('the_content', $second_part_of_story[1]);
    echo $second_part_of_story;   ?>
    Thread Starter Rich Owings

    (@gpsmapper)

    Thanks so much for taking the time to share this! My PHP skills are still at the newbie level, so if you don’t mind a couple of beginner questions…

    1. I can just replace <?php the_content(); ?> with the code above, right?
    2. Do I just replace // here ‘something’ code // with my code or text? I tried that but got an unexpected T_STRING error on that line.

    Thanks again. I really appreciate this very much.

    1. yes
    2. probably some mismatched opening and/or closing php tags.
    the above code is fully inbetween <?php opening tag and closing tag ?>

    so if your code is just php, you have to enter it without php tags.

    if you include html tags, you could either echo them from the php, or you have to very aware how to close and open the php tags before and after the html tag.

    if it is nothing too secret, it would be the best if you could post your code here.

    Thread Starter Rich Owings

    (@gpsmapper)

    Thanks. What I have right now is just this…

    <!-- BEGIN MORE TEST -->
    					<?php  $story = get_the_content();
    $story = explode('<span id="more',$story);
    $first_part_of_story = $story[0];
    $second_part_of_story = $story[1];
    $first_part_of_story = apply_filters('the_content', $first_part_of_story);
    echo $first_part_of_story;
    if ($second_part_of_story) {
    TEST MORE BREAK ;
     } ;
    $second_part_of_story = explode('</span>',$second_part_of_story);
    $second_part_of_story = apply_filters('the_content', $second_part_of_story[1]);
    echo $second_part_of_story;   ?>
    
    <!-- END MORE TEST -->

    change this:

    if ($second_part_of_story) {
    TEST MORE BREAK ;
     } ;

    into:

    if ($second_part_of_story) {
    echo 'TEST MORE BREAK' ;
     } ;

    edit: ignore the first part of this reply. i had a mistake in the code (the position of the closing bracket of the if condition) – corrected:

    <?php  $story = get_the_content();
    $story = explode('<span id="more',$story);
    $first_part_of_story = $story[0];
    $second_part_of_story = $story[1];
    $first_part_of_story = apply_filters('the_content', $first_part_of_story);
    echo $first_part_of_story;
    if ($second_part_of_story) {
    echo 'TEST OF MORE TAG' ;
    $second_part_of_story = explode('</span>',$second_part_of_story);
    $second_part_of_story = apply_filters('the_content', $second_part_of_story[1]);
    echo $second_part_of_story;
    }
     ?>

    Thread Starter Rich Owings

    (@gpsmapper)

    That worked. Thank you so much!

    It’s really awesome that folks like you take the time to help people here. It’s one of the things I love about the WP community.

    tr3ndy

    (@tr3ndy)

    Hi alchymyth,
    I’ve another problem: i would try to automatically insert some code (banner, text…) in the middle of the post. There’s a way to get number of characters of the post, divide by 2, and then add the code, after the (characters/2)+1?

    I.e.: post of 1000 characters, automatically add some text, at the 501th character… any ideas on that? Is it possible to do…?

    Thanks in advance, for your time!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Customizing AFTER the more tag’ is closed to new replies.