0
基本的に、私はカスタムワードプレスのテーマに取り組んでいます。私がしようとしているのは、各カテゴリのアイコンを設定することです。ループが始まり、投稿にカテゴリがある場合は、割り当てられたアイコンが表示されます。今は正しいアイコンが表示されていますが、ポストのタイトルと発言はページの名前に変わりません。ここに私は3つの投稿数学、英語と歴史を持っているそれらのすべてが正しいアイコンを持っていますが、数学、英語、または歴史の代わりにブログの投稿ページの名前を表示します。カテゴリアイコンを使ってPHP後ループを作成する方法
トップは私の基本レイアウトであり、ループをつかむ。下の一つは、私のループあなたのループファイルで
<?php
// Standard Post Format
?>
<?php $bgImage = get_the_post_thumbnail_url(); ?>
<div class="column one-third" style="background-image:url(<?php echo $bgImage; ?>);">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="nws-img">
<?php
// Find the first category the post is in.
$categories = get_the_category();
$category = $categories[ 0 ]->term_id;
$imgargs = array(
'cat' => $category,
'post_status' => 'inherit',
'post_type' => 'attachment',
'posts_per_page' => '1'
);
$imgquery = new WP_Query($imgargs);
if ($imgquery->have_posts()) {
while ($imgquery->have_posts()) { $imgquery->the_post(); ?>
<div class="category-featured-image">
<?php echo wp_get_attachment_image($post->ID, 'thumbnail'); ?>
</div>
<?php
}
}
// Reset postdata to restore ordinal query.
wp_reset_postdata();
?>
</a>
<div id="content-box">
<h1> <a href="<?php the_permalink(); ?>" > <?php the_title(); ?> </a> </h1>
<?php the_excerpt(); ?>
</div>
</div>
まあのように見える必要があります変更が仕事をした、最後の部分にあなたに感謝しますが、問題は、今これである: