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:
https://www.transycan.net/blogtest/2005/07/05/integrate/2/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 https://www.stevengpeterson.com 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\" rel=\"bookmark\">$wp_title</a></h3> <div class=\"meta\">$_eFiled $wp_category — $wp_author @ $wp_time </div> <div class=\"storycontent\"> $wp_content </div> <div class=\"feedback\"> </div> </div> endwhile; else: $wp_apology = _e('Sorry, no posts matched your criteria.'); $display .= "<p>$wp_apology</p>"; endif; $display .= " </div>";
- The topic ‘Import WordPress Posts into a Pre-Existing PHP Site Layout!’ is closed to new replies.