私は学校のプロジェクトで、新聞から RSS フィードを取得し、それらを組積造レイアウトでスタイル化することに取り組んでいます。Simplepieクラスを使用して html に変換する RSS フィードを取得できますが、各記事にカウンター付きの 1 から 5 までの列サイズを指定したいと考えています。
これは私がhtmlで得るものです:
<div class="post col1 col2 col3 col4 col5 col1 col2 col3 col4 col5"> <!-- begin post -->
<h3 class="title"><a href="http://feedproxy.google.com/~r/dso-nieuws-sport/~3/zfFYeKYGagk/detail.aspx">Bergen naar halve finales play-offs basket</a></h3>
代わりに、最初の記事にクラス「post col1」、2 番目の記事に「post col2」、5 つの記事の後、6 番目の記事に再び「col1」などを取得する必要があります。
これは私のPHPコードです:
<?php if ($sportfeed->data): ?>
<?php $sportitems = $sportfeed->get_items(); ?>
<?php foreach($sportitems as $sportitem): ?>
<?php $enclosure = $sportitem->get_enclosure(0); ?>
<?php if ($enclosure):?>
<div class="post
<?php $teller = 1;
for ($i = 1; $i <= 10 /* aantal artikels in feed */; $i++) {
if ($teller == 1) {
echo " col1";
++$teller;
} else if ($teller ==2)
{
echo " col2";
++$teller;
} else if ($teller ==3)
{
echo " col3";
++$teller;
} else if ($teller ==4)
{
echo " col4";
++$teller;
} else
{ echo " col5";
$teller =1;
}
}?>"> <!-- begin post -->
<h3 class="title"><a href="<?php echo $sportitem->get_permalink(); ?>"><?php echo $sportitem->get_title(); ?></a></h3>
<img src ="<?php echo $enclosure->get_link(); ?> "class="img_artikel"/>
</div> <!-- einde post -->
<?php endif; ?>
<?php endforeach; ?>
よろしくお願いします!私のプロジェクトを進行させるには、大きな意味があります。