1
I have a PHP code that takes the content from a feed, I would like to separate that content into two Divs. For example: in the div1 will be the first five posts on a Carousel (jcarousel) and on div2 will be another five posts on a listing.
<?php
// loalidade BR e idioma pt_BR
setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese") or die('Locale not installed');
date_default_timezone_set('America/Sao_Paulo');
$rss = new DOMDocument();
$rss->load('https://jovemnerd.com.br/nerdnews/feed/');
$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);
}
<div class='box'>
$limit = 5;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
// aqui foi alterado para a função com a formatação correta
$date = strftime("%A, %d de %B de %Y", strtotime($feed[$x]['date']));
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<small><em>'.$date.'</em></small></p>';
echo '<p>'.$description.'</p>';
}?>
This is the code that I take the contents of the RSS, but I have no idea how to separate it.
Thank you very much, man. But it gave this error here Parse error: syntax error, Unexpected '<' in /home/pennydreadful/public_html/test/index.php on line 33
– Felipe Viero Goulart
Exchange the
<div class='div-1'>
forecho "<div class='div-1'>"
, has php and html code snippets together, so the error. Another option is to close the php tag before the<div class='div-1'>
and Bir again before thefor
– fernandoandrade
But then I wouldn’t have to change the structure of ""? I ask this because I don’t know PHP.
– Felipe Viero Goulart
Fix the above code as stated by fernadoandrade, html was mixed with PHP code.
– Edvaldo Farias
thank you @Edvaldofarias -now shows this error: Parse error: syntax error, Unexpected 'for' (T_FOR), expecting ',' or ';' in /home/pennydreadful/public_html/test/index.php on line 34
– Felipe Viero Goulart
What happens is that it doesn’t show 5 results per div, it shows many, look http://www.pennydreadful.com.br/test/
– Felipe Viero Goulart
@Felipestoker just limit the amount of the second
div
exchanging$x<count($feed);
for$x<=5;
for example.– fernandoandrade
The second DIV will also have the 5 item. I had understood that the rest of the feed was in the second div. Sorry for the bug.
– Edvaldo Farias
Note 10, thank you very much.
– Felipe Viero Goulart