Cache throws error when including wordpress posts outside of wordpress
-
Hi guys,
I display my WordPress posts by using the code below:
<script type="text/javascript"> function toggle_blog_entry(entryID) { var div = document.getElementById(entryID); var button = document.getElementById("link_" + entryID); var dataContent = div.getAttribute("data-content"); var dataExcerpt = div.getAttribute("data-excerpt"); if (button.innerHTML == "[Read More]") { div.innerHTML = dataContent; button.innerHTML = "[View Less]"; } else { div.innerHTML = dataExcerpt; button.innerHTML = "[Read More]"; } } </script> </head> <body> <div id="header"> <?php require(dirname(_FILE_) . '/blog/wp-blog-header.php'); ?>
And then echoing it out in the page like below:
<?php $x = 0; $posts = get_posts('numberposts=3&order=DSC&orderby=post_date'); foreach ($posts as $post) : start_wp(); ob_start(); the_permalink(); $permalink = ob_get_contents(); ob_end_clean(); echo "<h2 "; if ($x == "0") echo "class=\"first\""; echo "><a href=\"$permalink\">";?> <?php the_title(); echo "</a></h2>"; ?> <?php echo '<p class="small">'; the_time('F j, Y g:i a'); echo " by "; echo the_author_posts_link(); echo '</p>'; ?> <?php ob_start(); the_content(); $content = ob_get_contents(); ob_end_clean(); ob_start(); the_excerpt(); $excerpt = ob_get_contents(); ob_end_clean(); $szHTML = "<div class=\"font\" id=\"blog_entry_$x\" data-excerpt=\"".htmlspecialchars($excerpt, ENT_QUOTES)."\" data-content=\"".htmlspecialchars($content, ENT_QUOTES)."\">"; if ($content != $excerpt) $szHTML .= $excerpt . "</div><p align=\"right\" style=\"font-size:13px\"><a href=\"#\" onclick=\"toggle_blog_entry('blog_entry_$x');return false;\" id=\"link_blog_entry_$x\" class=\"home_blog_excerpt_links\">[Read More]</a> - <a href=\"$permalink\" class=\"home_blog_excerpt_links\">[View Post and Comment]</a></p>"; else { $szHTML .= $excerpt . "</div></font><p align=\"right\" style=\"font-size:13px\"><a href=\"$permalink\">[View Post and Comment]</a></p>"; } print $szHTML; ?> <?php $x++; endforeach; ?>
But when I then go visit my page with that I’m loading the posts in I get the error below:
Warning: Cannot modify header information - headers already sent by (output started at /home/mooashc1/public_html/mooash.me/index.php:64) in /home/mooashc1/public_html/mooash.me/blog/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 88
Is there a way to fix this?
- The topic ‘Cache throws error when including wordpress posts outside of wordpress’ is closed to new replies.