如何为链接的url设置if()语句


How do I set if ( ) statement for the url of a link?

如何为链接的url而不是当前页面设置if/else条件?

我在这个代码的第4行遇到问题:

$args = array( 'post_type' => 'studies', 'posts_per_page' => 4 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
**if(url=the page I want to link to)** 
echo '<a href="'.get_permalink().'">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</a>';
else
echo '<a href="#self" class="anchor-hover">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</a>';
endwhile;

将url强制转换为字符串,然后为字符串

运行if语句

尝试使用==运算符。例如,将第4行替换为:

if ( get_permalink() == 'http://example.com' )