我在Wordpress循环中有这段代码,用于检查字段'quote'是否存在。如果它不在这里它将显示链接,但如果它在那里它不会。
<?php
if(get_field('quote') == ''){
$yourTag = "<a href="the_permalink();">" ;
} else {
$yourTag = "";
}
?>
然后我用它来输出链接:
<div> <?php echo $yourTag; ?> </div>
我遇到的问题是第3行:
$yourTag = "<a href="the_permalink();">" ;
所有这一切都是将the_permalink()添加到URL的末尾,并且不输出实际的链接。
这段代码是否正确?
作为参考,完整的循环代码在这里:
<!-- Main Loop =========================================== -->
<div class="container blog-card-container">
<div class="card-columns">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- Conditional a =========================================== -->
<?php
if(get_field('quote') == ''){
$yourTag = "<a href="the_permalink();">" ;
} else {
$yourTag = "";
}
?>
<div> <?php echo $yourTag; ?> </div>
<div class="card">
<!-- Image if loop =========================================== -->
<?php if ( in_category('14') ) : ?>
<div class="client-header-logo-card" style="background-color: <?php the_field('client_brand_colour'); ?>;">
<?php
$image = get_field('client_logo');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
<?php else: ?>
<div class="blog-thumb-container">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
</div>
<?php endif ?>
<!-- Meta Data if loop =========================================== -->
<div class="blog-clients-card-block">
<?php if ( in_category('14') ) : ?>
<div class="client-text-block">
<p class="blog-cat-label"><?php the_category(', '); ?></p>
<h2><?php the_title(); ?></h2>
<?php if( get_field('quote') ): ?><p class="client-quote"><span style="color:<?php the_field('client_brand_colour'); ?>; font-weight:bold;">“ </span><?php the_field('quote'); ?><span style="color:<?php the_field('client_brand_colour'); ?>;font-weight:bold;"> ”</span></p><?php endif; ?>
<?php if( get_field('quote_name') ): ?><p class="client-name" style="color:<?php the_field('client_brand_colour'); ?>;"><?php the_field('quote_name'); ?></p><?php endif; ?>
<?php if( get_field('quote_position') ): ?><p class="client-position" style="color:<?php the_field('client_brand_colour'); ?>;"><?php the_field('quote_position'); ?></p><?php endif; ?>
<?php if( get_field('button_text') ): ?>
<a class="btn btn-sm btn-client-archive" href="<?php the_permalink(); ?>" style="background-color:<?php the_field('client_brand_colour'); ?>;" role="button"><?php the_field('button_text'); ?></a>
<?php endif; ?>
<?php if( get_field('video_url') ): ?>
<div class="embed-container">
<?php the_field('video_url'); ?>
</div>
<?php endif; ?>
</div>
<?php else: ?>
<p class="blog-cat-label"><?php the_category(', '); ?></p>
<h2 class="blog-card-title"><?php the_title(); ?></h2>
<p class="card-text"><?php the_excerpt(__('(more…)')); ?></p>
<p><strong><?php the_author(); ?></strong> | <?php the_date(); ?> </p>
<?php endif ?>
</div>
</a>
</div>
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
</div>
答案 0 :(得分:0)
您可以使用点(.)
,即concatenation operator,如下所示。
<?php
if(get_field('quote') == ''){
$yourTag = "<a href='".get_the_permalink()."'>" ;
} else {
$yourTag = "";
}
?>