繁体   English   中英

如何为链接的网址设置if()语句?

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

如何为链接的URL(而非当前页面)设置if / else条件?

我在这段代码的第四行遇到麻烦:

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

将网址转换为字符串,然后对该字符串运行if语句

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM