Wordpressでニュースサイトを開発しています。最初の3つの記事をブートストラップカルーセルに表示する必要があります。私の問題は、 3つの要素のうちの最初の段階でのみ "アクティブな"クラスを作成することができますが、実際にどのようにするかわかりません。私はすでにこのサイトで見つけた答えは(これを)試したカルーセルの最初の要素に「アクティブ」クラスを追加する方法
<?php
$args = array('numberposts' => '3');
$recent_posts = wp_get_recent_posts($args);
foreach ($recent_posts as $recent) {
echo '<div class="item active"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
}
?>
:ここに私のコードは
$isFirst = true;
foreach ($recent_posts as $recent) {
echo '<div class="item' . $isFirst ? ' active' : '' . '"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ": <strong>" .$recent["post_title"] . '</strong></a></div>';
$isFirst = false;
?>
が、それはちょうど私に「アクティブ」の言葉を印刷しました。あなたの助けのための
おかげで
欠落している閉じ括弧は意図的ですか? – Pete
ええ、ちょうどあなたにコードを表示する... hahaha –