tags:

views:

328

answers:

3

I'm trying, but I'm stucked with the logic... so, I have this:

$max_items=10;

echo '<table>';
echo '<tr>';

foreach ($feed->get_items(0, $max_items) as $item): 

echo '<td>';
echo $some_value; 
echo '</td>';

endforeach; 

echo '</tr>';
echo '</table>';

I want to show the results like this:

[1][2]
[3][4]
[5][6]
[7][8]
[9][10]

I have to use a while statement? A for loop? Inside or outside the foreach code?

I really don't get it...

Thanks for any kind of help

A: 

Take a look at this link to Displaying Recent Posts On a Non-WordPress Page. I think what you may be looking for is a way to loop over the objects get methods. For that you will need a nested loop and some sort of reflection.

zodeus
Nope.. but thanks, I already have simplePie working fine with custom fields and customized atom tags. I just don't know how to break the results in different rows... I need some rest and more php lessons.
A: 

I was just recently working with SimplePie on the February release of Cogenuity so this is still fresh in my mind.

  • Your $some_value variable never gets initialized.
  • The $item object will have such methods as get_permalink(), get_title(), get_description(), and get_date()
Glenn
Hi Gleen, thanks! But this is a snippet of my code.. I have something like this before that piece:$max_items =10;$feed = new SimplePie();$feed->set_feed_url(array( 'http://xxxx.com/test/tag/destaque/?feed=atom' ));$feed->set_item_class('SwapDates'); $feed->strip_htmltags(false);
A: 

Here's a very simple example of how to do this sort of HTML building.

<?php

$data = range( 'a', 'z' );
$numCols = 2;

echo "<table>\n";
echo "\t<tr>\n";

foreach( $data as $i => $item )
{
    if ( $i != 0 && $i++ % $numCols == 0 )
    {
     echo "\t</tr>\n\t<tr>\n";
    }
    echo "\t\t<td>$item</td>\n";
}

echo "\t</tr>\n";
echo '</table>';

This way, you can change $numCols to be 3 or 4 (or any number) and always see that number of columns in the output, and it does so without using an nested loop.

Peter Bailey
thanks Peter!!! that Modulo operator and that $i => $item works 100%, really thanks