Mini loop on home page: post not formatting (3 posts)

  1. pcwp
    Posted 9 years ago #

    I'm using a mini loop on a home page.
    ver 2.03

    The post title is fine (in h2 tags),
    but the post content is one block of
    unformatted text - ignoring any format
    tags from the post such as br and p
    tags (the content is fine on the blog).

    I've tried it both as a ul/li and plain.

    the print portion of the code is:
    \ <?
    $news=$wpdb->get_results("SELECT ID,post_title,post_content,post_excerpt FROM $wpdb->posts
    WHERE post_status= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($news as $np){
    print ("<a href=\"");
    echo get_permalink($np->ID);
    print ("\"><h2>$np->post_title</h2>");
    print ("$np->post_content");
    } ?> \

    thanks for any direction.

  2. You're bypassing all the built in formatting functions with that code. A better way would be to write a proper Loop, but that may be too problematic for whatever you're doing.

    So, the quick fix is to change the next to last line to this:
    print (apply_filters('the_content',$np->post_content));

    You should also probably apply 'the_title' filters to the post title.

  3. pcwp
    Posted 9 years ago #

    beautiful Otto,

    while I aspire to write a "proper Loop",
    I opted for your quick fix which gave me
    exactly what I wanted.

    thank ya kindly!

Topic Closed

This topic has been closed to new replies.

About this Topic