Support » Plugins » Import WordPress Posts into a Pre-Existing PHP Site Layout!

  • On my portfolio-site I wanted to have word-press maintain the short “news and updates” posts on my front page. The goal is to have WordPress do the heavy-lifting and THEN transparently pull the posts into the external web-site with a little php-magic!

    The starting point to accomplish this is here:

    This may only take you half-way though. I dynamically build my entire page FIRST storing all output into a php-variable as a string. Only when the page is complete do I print the whole thing in one shot.

    The Major Problem:
    Most of WordPress’s ‘Template-Tag’ functions “echo” their output rather than sensibly returning a value. I suppose somebody skipped the class on ‘Get_member() and Set_member() functions…

    Regardless, for some ‘Template-Tag’ functions the final parameter is a boolean value to toggle ‘display’. Use FALSE to GET the value and store it.

    Other functions employ other tricks. For ‘the_tag()’ you may be simply be able to use ‘get_tag()’ or ‘get_the_tag()’ in some cases. In others more work is needed.

    Searching the WordPress web-site docs, and forums reviles the solution to all of these but you will have to work for it.

    The End
    This took much longer than I wanted to spend on it, so not- much explanation but here’s some PHP to help the next guy in-line.

    This will be in action on probably later this week. Right now all updates are on the private-dev-site.

    /* WordPress Integration
       $display .= "<div>";
    if (have_posts()) : while (have_posts()) : the_post();
    $wp_date = the_date('','<h3>','</h3>', false);
    $wp_postID = get_the_ID();
    $wp_permalink = get_permalink();
    $wp_title = the_title('','',false);
    $wp_author = get_the_author();
    $wp_time = get_the_time();
    $wp_content = apply_filters('the_content', get_the_content());
    $wp_category = "";
    foreach((get_the_category()) as $category) {
        $wp_category .= $category->cat_name . ', ';
       $display .= "$wp_date
          <div class=\"post\" id=\"post- $wp_postID\">
             <h3 class=\"storytitle\"><a href=\"$wp_permalink\"
             <div class=\"meta\">$_eFiled $wp_category —
                $wp_author @ $wp_time
             <div class=\"storycontent\">
             <div class=\"feedback\">
    endwhile; else:
    $wp_apology = _e('Sorry, no posts matched your criteria.');
       $display .= "<p>$wp_apology</p>";
       $display .= "
Viewing 3 replies - 1 through 3 (of 3 total)
  • wierd – some of my code is being truncated above if the line is too long. I clicked ‘edit’ and it’s all there, come back and it’s missing.

    Now the ‘edit’ is missing too…

    the content line for those who want it:

    $wp_content = apply_filters('the_content',

    It’s not truncated. Use the scroll bar at the bottom of your post. And the ‘edit’ link is temporary; you only get to edit your post for the first several minutes after posting it.

    ahh i see says the blind man.. 😛

    I’m under some pressure this week, so bare with me. I solved it and posted the solution – so we’ll call it a successful day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Import WordPress Posts into a Pre-Existing PHP Site Layout!’ is closed to new replies.