私が持っている<a></a>
私は、高度なカスタムフィールドから通じ引っ張ってるいくつかのコンテンツを囲む私のページにタグを。
これはすべて良いことですが、リンクを条件付きにしたいと思います。
コメントをお願いします。.client-quoteクラスがページにある場合は、タグを非表示にします。
ループコード全体は次のとおりです。
<!-- 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(); ?>
<?php if( get_field('quote') ): ?>
<a href="<?php the_permalink(); ?>">
<?php endif; ?>
<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>
<?php if( get_field('quote') ): ?>
</a>
<?php endif; ?>
</div>
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
</div>
私は次のようにリンクの周りにifタグを追加しようとしました:
<?php if( get_field('quote') ): ?>
<a href="<?php the_permalink(); ?>">
<?php endif; ?>
CODE AND CONTENT HERE
<?php if( get_field('quote') ): ?>
</a>
<?php endif; ?>
しかし、これは機能していないようです。ループ内のループの前に実行される可能性があるためだと思いますか?少し混乱します...ページが読み込まれた後に実行する関数などが必要なのかもしれません。完全にはわかりません。
それが私を怒らせているので、どんな助けでも大いに感謝します!
phpチェックを実行して、そこにあるかどうかを確認し、結果を変数($ yourTag)に入れます。その後、あなたの体のどこにでもそれをエコーします。
<?php
if(get_field('quote') == ''){
$yourTag = "<a href=\"".get_the_permalink()."\">" ;
} else {
$yourTag = "";
}
?>
次に、このようにHTMLの好きな場所に配置します
<div> <?php echo $yourTag; ?> </div>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加