• Hi all,

    When I think about it, I would basically want to see that ‘the_content’ will be split in three sections, f.i.:

    – the first paragraph;
    – the featured image with caption text;
    – the rest of ‘the_content’.

    Can you help me out on this?

    Because I have already tried this:

    ?php // original content display
            // the_content();
        // split content into array
            $content = split_content();
        // output first content section in intro
            echo '<div id=”intro">', array_shift($content), '</div>';
        // output featured image after intro
    if( sdw_get_option( 'lay_a_fimg' ) && ( !$format || ($format && sdw_get_option('lay_a_format') == 'icon') ) && $fimg = sdw_featured_image('sdw-lay-a') ):
           echo $fimg;
    if(sdw_get_option( 'lay_a_fimg_cap' ) && !$format && $caption = get_post(get_post_thumbnail_id())->post_excerpt) : ?>
    
    <figcaption>
     <?php echo $caption; ?>
    </figcaption>
    endif; 
    
        // output remaining content sections in column2
            echo '<div id=”restofcontent">', implode($content), '</div>';
    ?>

    And that does not seem to work.

    Hoping to hear from you soon.

    Kindest regards,
    Irene
    https://www.mightymusings.nl

Viewing 2 replies - 1 through 2 (of 2 total)
  • what is the exact code of that function split_content() ?

    what is the result of your trial?

    also, you have the ‘wrong’ kind of double quotes in the code; make sure to have only " or ', not

    where is $format and $fimg defined?

    if you posted only part of the code, please post the full code of the template.
    – are you editing single.php of your theme?

    what theme are you working with?

    Thread Starter iPixtitude

    (@pixelprinses)

    I found this piece of code (except the featured image coding) on the Internet. Google is my best friend…

    I have indeed changed the double quotes. Thanks for that.

    The $format and $fimg were defined in two files… but that does not matter anymore: I found a new snippet that I have put in the functions.php of my child theme (Sidewalk theme).

    The snippet I used is as follows:

    add_filter( 'the_content', 'insert_featured_image', 20 );
    
    function insert_featured_image( $content ) {
    
        $content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->ID, 'post'), $content, 1 );
        return $content;
    }

    Thanks a lot for your efforts on this issue.

    Regards,
    Irene

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Split 'the_content' in three separate sections’ is closed to new replies.