0

別のスタイルを介して呼び出す特定の投稿に別のクラスを追加しようとしています。私は post_class 関数を少しいじりましたが、これをどのように達成できるのか、まだほとんど手がかりがありません。

<?php if (have_posts()) : ?>
<?php $c = 0;while (have_posts()) : the_post(); $c++;
if( $c == 3) {
    $style = 'third';
    $c = 0;
}
else $style='';
?>
<div <?php post_class($style) ?> id="post-<?php the_ID(); ?>">

これを追加してみました。背景とテキストの色を変更しただけのカスタムスタイルを作成しました

これらを使用して、ホームページで投稿がどのように見えるかを編集することはできますか?

4

4 に答える 4

0

ループの外側:

$classes = array(
    0=>'first-column',
    1=>'second-column',
    2=>'third-column'
);
$i = 0;

あなたのループで:

<article id="post-<?php the_ID(); ?>" <?php post_class($classes[$i++%3]); ?>>

次のような出力:

<article class="first-column format-standard hentry category-uncategorized">
<article class="second-column format-standard hentry category-uncategorized">
<article class="third-column format-standard hentry category-uncategorized">
<article class="first-column format-standard hentry category-uncategorized">
<article class="second-column format-standard hentry category-uncategorized">
<article class="third-column format-standard hentry category-uncategorized">
于 2013-06-05T10:40:49.300 に答える
0
<div <?php post_class($style) ?> id="post-<?php the_ID(); ?>">

firebug を使用するか、ソースを表示して、このコードが作成しているクラス名を確認してください。おそらく次のように表示されます。

<div class="divclassname" id="post-206">

ここで、ページにロードされた css スタイルシートで、次のように、class (divclassname) または id (post-205) の値に基づいて新しいルールを作成する必要があります。

.divclassname {
background-color: #f3f3f3;
color: #ffffff;
}

#post-205 {
background-color: #cccccc;
color: #a19402;
}
于 2013-06-05T10:42:09.867 に答える
0
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2 id="post-<?php the_ID(); ?>">
于 2013-06-05T10:39:11.653 に答える