Forums

Wordpress posts outside of the install directory (8 posts)

  1. ShortyR19
    Member
    Posted 3 years ago #

    I am attempting to put wordpress posts on my front page. My wordpress blog is located in a "blog" subdirectory while my website's homepage is in the web root. I wrote my own SQL query to call the WP database and grab the appropriate posts, their dates, etc. From there it is inserted directly onto the page; no WP functions are used, just the straight SQL/PHP statements. I am using WP 2.0.1.

    However, when I place the data on the page the normal formatting is lost. Looking at the db a bit I see that line breaks are literally in the db, not in html tags. Also, I am seeing wierd characters were I have double spaces between sentences.

    From the research I've done I'm guessing I need to use WP's wpautop function and maybe something else.

    My question is: What functions do I need to use and how do I go about importing them into this new page outside of the wp/blog directory?

    Thanks for your help.

  2. Kafkaesqui
    Moderator
    Posted 3 years ago #

    See the information on integrating WordPress in a non-WP document found on the Codex:

    http://codex.wordpress.org/Creating_a_Static_Front_Page#Integrating_WordPress

  3. ShortyR19
    Member
    Posted 3 years ago #

    This is essentially what I had before. I am able to extract the data fine but it doesn't format it correctly.

  4. ShortyR19
    Member
    Posted 3 years ago #

    To clarify: I want to apply the same formatting that the_content() gets in the regular Wordpress Loop.

  5. Kafkaesqui
    Moderator
    Posted 3 years ago #

    Try something like:

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

    Replace $post with whatever object var used in your code. Alternatively, you can choose which of the various filters to apply to your content:

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

    This (link refer) will bypass any formatting done by plugins.

  6. ShortyR19
    Member
    Posted 3 years ago #

    Very good. That got it to work. Thanks for the helpful replies.

    Final piece of the puzzle then: All of my double spaces between sentences (made using the rich text editor) have a  and a single space rather than two spaces.

    Any ideas?

  7. ShortyR19
    Member
    Posted 3 years ago #

    For reference, this is the code that I am using:


    <?php
    require_once("blog/wp-config.php"); // Change this for your path to wp-config.php file

    $sql = 'SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_content, wp_posts.post_date'
    . ' FROM wp_post2cat INNER JOIN wp_posts ON wp_post2cat.post_id = wp_posts.ID'
    . ' WHERE (((wp_post2cat.category_id)=3)) AND wp_posts.post_status= "publish"'
    . ' ORDER BY wp_posts.post_date DESC LIMIT 10';

    $result = mysql_query ($sql);

    while ($news = mysql_fetch_array
    ($result, MYSQL_ASSOC)) {
    echo "<h3>{$news['post_title']}</h3>
    <p><i>{$news['post_date']}</i></p><p>";
    echo apply_filters('the_content',$news['post_content']);
    echo "</p></br>n";
    }
    ?>

  8. ShortyR19
    Member
    Posted 3 years ago #

    Alright, I got it figured out. It seems the  thing had something to do with an older version of the K2 Theme. The new one works fine.

Topic Closed

This topic has been closed to new replies.

About this Topic