WordPress.org

Ready to get started?Download WordPress

Forums

Remove the `<p> tag in template tag the_content? (14 posts)

  1. fredrik
    Member
    Posted 9 years ago #

    I've got two instances of The Loop on my front page. One howing the main feed and another one showing short post from another category.

    In the second instance of the loop I'm displaying the items in an unordered <li> list so I don't want to use the <p>tag that comes included in the tags default output. Is there template tag option to exclude that p-tag or do I have to manually delete that from the code?

  2. Kafkaesqui

    Posted 9 years ago #

    Instead of the_content() tag, try this:

    <?php echo $post->post_content; ?>

    This will display post content "raw", in that it won't make use of any of the auto-formatting functions. But if you need that, there's a way around that as well.

  3. fredrik
    Member
    Posted 9 years ago #

    That method seemes to be working perfectly for my purposes. Thanks very much Kafkaesqui!

  4. etoile
    Member
    Posted 9 years ago #

    Ah! Somebody else had this problem, too. Now for my question: how can this method be used with teaser text? That is, I want to use extended entries, but the fix given above sounds like it's just going to print the whole entry all the time.

  5. etoile
    Member
    Posted 9 years ago #

    Any thoughts on doing this while preserving the teaser text, folks? :)

  6. atdilts
    Member
    Posted 9 years ago #

    thanks, Kafkaesqui... that worked well... but now i'm curious, how do you get the filters to apply, but without wrapping the whole thing in a tag? or better yet, selectively apply the filters?

  7. Lorelle
    Member
    Posted 9 years ago #

    Teasers, I think, are also known as asides, so you might find more information at http://codex.wordpress.org/Adding_Asides

  8. tomhanna
    Member
    Posted 9 years ago #

    etoile: I think you can do the same thing with the_excerpt if you want to just have the first 120 characters (or whatever it is) of the post. Is that what you mean by a "teaser"?

    Instead of

    <?php echo $post->post_content; ?>

    I think it would be

    <?php echo $post->post_excerpt; ?>

    If that works, thank Kafkaesqui and this thread.

    http://wordpress.org/support/topic/39146#post-220911

  9. Kafkaesqui

    Posted 9 years ago #

    Just a note that a teaser in WordPress terminology is the text before the <!--more--> Quicktag. Thought it important to toss that out there.

    Using echo $post->post_excerpt works only if there's an actual excerpt. It would display whatever is found in the post_excerpt column. Of course if that's what's being used for the "teaser," it'll work great.

    atdilts, you can apply filters individually by wrapping $post->post_content in the various filter functions, as shown here:

    http://wordpress.org/support/topic/35504#post-201193

    or you can hit them all at once (and thereby properly apply both internal and plugin filters on the content):

    <?php
    echo apply_filters('the_content', $post->post_content);
    ?>

  10. Joshua Sigar
    Member
    Posted 9 years ago #

    @Kafkaesqui,
    doesn't the code on the post above give the same output as <?php the_content(); ?>

  11. Kafkaesqui

    Posted 9 years ago #

    Not quite. For example, it ignores the <!--more--> Quicktag, as well as the post password, etc. It's just a way of bypassing the functionality specifically inherent in the_content() while still picking up the formatting. That is, if you *really* need to. :)

  12. Joshua Sigar
    Member
    Posted 9 years ago #

    Hmm, I see. But wpautop is still applied, though, which is not desired in this case.

  13. Kafkaesqui

    Posted 9 years ago #

    alphaoide, hence the link:

    http://wordpress.org/support/topic/35504#post-201193

    Just remove wpautop() from the function nesting.

  14. zpousman
    Member
    Posted 8 years ago #

    I see and understand the wpautop() function above. This is a lot of a work-around for just getting rid of the tags on each blog post. Is there a way for this to become a setting at some point. Seems like it would really be 2 settings: Keep WYSIWYG line breaks? { y | n } and Wrap posts in tags? { y | n }

Topic Closed

This topic has been closed to new replies.

About this Topic