WordPress.org

Ready to get started?Download WordPress

Forums

More tag, get content with formatting: text wrap @ image (6 posts)

  1. jami1955
    Member
    Posted 3 years ago #

    Simple problem, I've seen three forum threads about this, but nothing that goes withthe basic codex w/o core hacks. Here's the problem:
    I have a post, and in the post, BEFORE the MORE tag, there is an image, and 6 lines of text of the post wraps around the image which is floating left.

    I have the following code getting the picture and the first 6 lines, but no formatting, the text does NOT wrap around the image, which looks, well everybody knows how that looks.

    <?php
    global $post;
    $args = array( 'numberposts' => 1, 'offset'=> 0, 'category' => 6 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <p><?php echo apply_filters('the_content', _get_short_info($post->post_content)); ?></p>
    <?php endforeach; ?>

    Can anyone tell me what I need in that code that will get the formatting as well so the text wraps as well. BTW, I have this in the functions.php which defines the "_get_short_info" (not native to WP)

    function _get_short_info( $text ){
    	$t = explode('<!--more-->', $text);
    	return $t[0];
    }

    thanks,
    JSC

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Why don't you just use <?php the_content();?>?

  3. jami1955
    Member
    Posted 3 years ago #

    <?php the_content();?> returns the entire post, not the content before the MORE tag. The problem with the text not wrapping around the image I just solved by putting the "alignleft" class into the style sheet, and styling it so the image behaves. Why it was wrapping in the post and nowhere else I don't know, but now doesn't matter.

    As far as the MORE tag problem goes, specifically, what's in the HTML tab in the edit page for this post is:

    <a href="http://architekt-mm.de/wp-content/uploads/2011/05/sample1.jpg"></a><a href="http://architekt-mm.de/wp-content/uploads/2011/05/sample1.jpg">
    <img class="alignleft size-full wp-image-47" title="sample1" src="http://architekt-mm.de/wp-content/uploads/2011/05/sample1.jpg" alt="" width="150" height="100" /></a>Test post here for photo art. Test post here for photo art.Test post here for photo art.Test post here for photo art.Test post here for photo art.Test post here for photo art. <!--more-->

    That's 7 sentences. The 8th sentence is "THIS IS AFTER THE MORE TAG/" - and that sentence is present on the page where I want just the content that comes AFTER the more tag. So that call <?php the_content();?> is printing the entire post, not the snippet before the tag.

    Any solution?
    thanks!
    JSC

  4. jami1955
    Member
    Posted 3 years ago #

    ooops, the post above doesn't actually make sense, the last two sentences should read:
    The 8th sentence is "THIS IS AFTER THE MORE TAG/" - and that sentence is present on the page where I want just the content that comes BEFORE the more tag. So that call <?php the_content();?> is printing the entire post, not the snippet before the tag.

  5. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    <?php the_content();?> returns the entire post, not the content before the MORE tag.

    that depends on the setting of the variable $more:
    http://codex.wordpress.org/Customizing_the_Read_More

    and on the parameters in the_content():
    http://codex.wordpress.org/Function_Reference/the_content

  6. jami1955
    Member
    Posted 3 years ago #

    Cool, I will investigate these.

Topic Closed

This topic has been closed to new replies.

About this Topic