如何指定href =“'。get_permalink()。'”以允许某些链接并拒绝其他链接?

时间:2014-09-12 12:53:13

标签: php wordpress

以下代码适用于将自定义帖子类型的所有缩略图链接到其特定帖子。我需要做的是让一些人联系而不是其他人。如何设置参数以防止其中一些链接?

<?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; ?>

1 个答案:

答案 0 :(得分:2)

尝试以下代码

<?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; 
?>