Display posts on non wodpress page
-
Ok, I have a brand new install… summerlawns.com/blog/
and can see my rss feed xml here: https://www.summerlawns.com/blog/?feed=rss2
I have tried several different way to display the content on another page, located here:
https://www.summerlawnsinc.com/summerlawnsinc/blog.phpusing php code I found on this site, and other sites … however, no matter what I do, I cannot get past what is being displayed there now…like it is calling some default post metadata from the install files…
what am i missing here??
The code I am using is this:
`<?php
global $text, $maxchar, $end;
function substrwords($text, $maxchar, $end=’…’) {
if (strlen($text) > $maxchar || $text == ”) {
$words = preg_split(‘/\s/’, $text);
$output = ”;
$i = 0;
while (1) {
$length = strlen($output)+strlen($words[$i]);
if ($length > $maxchar) {
break;
} else {
$output .= ” ” . $words[$i];
++$i;
}
}
$output .= $end;
} else {
$output = $text;
}
return $output;
}$rss = new DOMDocument();
$rss->load(‘https://www.summerlawns.com/blog/?feed=rss2’); // <– Change feed to your site
$feed = array();
foreach ($rss->getElementsByTagName(‘item’) as $node) {
$item = array (
‘title’ => $node->getElementsByTagName(‘title’)->item(0)->nodeValue,
‘desc’ => $node->getElementsByTagName(‘description’)->item(0)->nodeValue,
‘link’ => $node->getElementsByTagName(‘link’)->item(0)->nodeValue,
‘date’ => $node->getElementsByTagName(‘pubDate’)->item(0)->nodeValue,
);
array_push($feed, $item);
}$limit = 10; // <– Change the number of posts shown
for ($x=0; $x<$limit; $x++) {
$title = str_replace(‘ & ‘, ‘ & ‘, $feed[$x][‘title’]);
$link = $feed[$x][‘link’];
$description = $feed[$x][‘desc’];
$description = substrwords($description, 100);
$date = date(‘l F d, Y’, strtotime($feed[$x][‘date’]));
echo ‘<p>‘.$title.’
‘;
echo ‘<small>Posted on ‘.$date.’</small></p>’;
echo ‘<p>’.$description.'</p>’;
}
?>
- The topic ‘Display posts on non wodpress page’ is closed to new replies.