WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How is post formatting done? (3 posts)

  1. MrBobDobolina
    Member
    Posted 7 years ago #

    Okay, I have my blog but it's separated from my main website (in a different subdomain.) Anyway, I would like to make it so the newest post always shows up on the main page. As of right now I have played with just connecting to the database and grabbing the needed info, but the main content of post contains no line breaks or returns.

    I know this is must be done via the PHP, but I can't find where. Is it possible for me to tap into the function that formats the paragraph breaks in? If so, how?

    Another option I have thought of would be *simply* set up a page on my blog, similar to a "single post" without the header, comments, sidebar, etc... and do an include of that into my home page. My only problem with that is that I don't know what functions are being called for in all the related documents that I would be ignoring.

    Any suggestions, comments, and/or questions would be most appreciative. Thanks a ton!

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    You don't need to access the database directly. You can use wordpress to do it all.

    In your external PHP page, just do:
    require('/your/blog/path/wp-blog-header.php');

    This includes all of the basic WordPress functionality. Then you can do something like this:

    $posts = get_posts( "numberposts=1" );
    if( $posts ) {
    foreach( $posts as $post ) {
    setup_postdata( $post );
    the_time('M d');
    the_title();
    the_content();
    ...whatever else you like...
    }
    }

    And so on. Including the wp_blog_header gives you the full wordpress suite. It won't actually display the blog itself unless you do a define('WP_USE_THEMES', true) first.

  3. MrBobDobolina
    Member
    Posted 7 years ago #

    Thank you kindly!

Topic Closed

This topic has been closed to new replies.

About this Topic