0

Loops と Wordpress の機能に取り組んだ後、これが と を使用して「注目の」画像を自動的に表示する唯一の方法でしalt == excerpttitle == title

これが最も効率的な方法ですか?

<?php
query_posts(array('category_name' => 'Featured')); 
    if (have_posts()) : while(have_posts()) : the_post();
    $alt = get_the_excerpt();
    $title = get_the_title();
    the_post_thumbnail( 'full', array('alt' => $alt, 'title' => $title, 'class' => 'bigImg') ); 

    endwhile; endif; 
?>

私を最も悩ませているのは、ループで抜粋とタイトルを定義しているという事実です。そのため、ループでもハッシュ配列を表示する必要があります。それについては、私とうまく合わないことがあります。

4

2 に答える 2

1

実際には、を使用でき、<?php the_excerpt(); ?>それらを定義する必要はありません<?php the_title(); ?><?php the_excerpt(); ?>

注目の投稿を 1 つ表示していると仮定しています。HTML と CSS を追加して、ループのスタイルを設定してみませんか? 以下は私が使用するものです。

<?php query_posts( '$cat=1' . '&posts_per_page=1' );
        if (have_posts()) : while (have_posts()) : the_post(); ?>

<article class="column">

<div class="thumbnail"><?php echo get_the_post_thumbnail($page->ID, array(254,254), 'thumbnail'); ?></div>
    <h2 class="title"><?php the_title(); ?></h2>
       <div class="post">
        <p>Posted in <a href="<?php $category = get_the_category();?>">
        <?php echo $category[0]->cat_name;?></a> <br />on <?php the_time('d/m/Y'); ?></p>
       </div>
    <p><?php the_excerpt(); ?></p>
</article>
<?php endwhile;?>
<?php endif;?>

$catはカテゴリであり、「おすすめ」のカテゴリは何ですかというワードプレスから見つけることができます。複数の投稿を表示したい場合は、&posts_per_page=1を好きな数に変更できます。

于 2013-07-28T19:52:40.517 に答える