Support » Fixing WordPress » Mini loop on home page: post not formatting

  • 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    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.

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Mini loop on home page: post not formatting’ is closed to new replies.