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

Viewing 7 replies - 1 through 7 (of 7 total)
  • See the information on integrating WordPress in a non-WP document found on the Codex:

    https://codex.www.ads-software.com/Creating_a_Static_Front_Page#Integrating_WordPress

    Thread Starter shortyr19

    (@shortyr19)

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

    Thread Starter shortyr19

    (@shortyr19)

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

    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:

    https://www.ads-software.com/support/topic/35504#post-201193

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

    Thread Starter shortyr19

    (@shortyr19)

    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?

    Thread Starter shortyr19

    (@shortyr19)

    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";
    }
    ?>

    Thread Starter shortyr19

    (@shortyr19)

    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WordPress posts outside of the install directory’ is closed to new replies.