下面的代码用于将自定义帖子类型的所有缩略图链接到它们的特定帖子。我需要做的是允许一些链接,而另一些则不允许。如何设置一个参数来阻止其中一些链接?
<?php $args = array( 'post_type' => 'casestudies', 'posts_per_page' => 18 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="casestudy"><a href="'.get_permalink().'" class="anchor-hover">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</a></div>';
endwhile; ?>
尝试以下代码
<?php
$args = array( 'post_type' => 'casestudies', 'posts_per_page' => 18 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
if($shouldlink) // your condition to check it should link or not
echo '<div class="casestudy"><a href="'.get_permalink().'" class="anchor-hover">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</a></div>';
else
echo '<div class="casestudy">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</div>';
endwhile;
?>