我正在创建投资组合页面。 &安培;我必须动态生成" id"用于图像[thumbnail]& " REL"对于锚标签。所以我可以连接它们。但我不知道该怎么做。
这是我目前的porofolio代码:
<div class="main-interior portfolio" id="portfolio-big-pics" style="display: block;">
<?php $args = array( 'post_type' => 'portfolio', 'order' => 'ASC');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $extraLastClass = $loop->current_post + 1 === $loop->post_count ? ' main-image-porfolio-main' : '';?>
<?php the_post_thumbnail( "thumbnail", array( "class" => "main-image portfolio $extraLastClass" ) ); ?>
<?php endwhile; ?>
<?php rewind_posts(); ?>
<div class="portfolio-box">
<h5>Portfolio</h5>
<ul class="item-list" id="portfolio-list">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
我还添加了一个截图,以便更好地理解。
答案 0 :(得分:1)
只需简单使用属性数组:
$attributes = array(
"class" => "main-image portfolio " . $extraLastClass,
"rel" => "whatever rel you want",
'id' => 'whatevere id you want',
'whatever attribute you want' => 'whatever value for that attribute'
);
the_post_thumbnail("thumbnail", $attributes);
修改强>
如果您想将其添加到您的链接,那么只需简单修改:
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
到
<li><a href="<?php the_permalink(); ?>" rel="<?php echo $post->ID; ?>" id="<?php echo $post->ID; ?>"><?php the_title(); ?></a>
其中$post
是您的帖子对象。
正如我所看到的那样(从你之前的问题开始),你并没有在标题上循环。