1
이미지 메타 데이터에 사용자 정의 필드를 추가하고 원래 메타 데이터 필드 (이미지, 캡션, 대체 텍스트)를 숨겼습니다. 그래서 내 새로운 맞춤 필드는 제목, 설명, 크기입니다.ACF 필드가 나타나지 않습니다.
ACF 전에 내 템플릿 같은했다:
이foreach($images as $image): ?>
<figure>
<a href="<?php echo $image['url']; ?>"><img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /></a>
<figcaption>
<p><?php the_field('title'); ?></p>
<p><?php the_field('description'); ?></p>
<p><?php the_field('dimensions'); ?></p>
</figcaption>
</figure>
<?php endforeach; ?>
<?php endif; ?>
이제 내 코드는 바로 출력되어, 나는이에 제목, 내림차순 및 희미한 필드를 변경
<?php if (is_single()) : ?>
<h1><?php the_title(); ?></h1>
<?php else : ?>
<h1>
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>
<?php endif; // is_single() ?>
<h3><?php ffm_artists(); ?></h3>
<h3><?php date_range(); ?></h3>
<?php if (has_post_thumbnail() && ! post_password_required()) : ?>
<div class="entry-thumbnail">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_post_thumbnail("large"); ?></a>
</div>
<?php endif;
the_content('Read more...');
$images = get_field('images'); if($images):
foreach($images as $image): ?>
<figure>
<a href="<?php echo $image['url']; ?>"><img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /></a>
<figcaption>
<?php if($image['title'] !== '') { echo $image['title'], '<br />'; }?>
<?php if($image['caption'] !== '') { echo $image['caption'], '<br />'; }?>
<?php if($image['description'] !== '') { echo $image['description']; }?>
</figcaption>
</figure>
<?php endforeach; ?>
<?php endif; ?>
ACF를 필드를 추가 한 후 blank <p><\p>
Title, Desc 및 Dims 필드 안에 텍스트가 있다는 것을 알고 있습니다. 이견있는 사람?
감사합니다. Tim. 그래도 이미지의 ID는 모르지만 루프를 통해 실행됩니다. 정확한 ID를 지정하지 않고 루프의 이미지의 현재 ID 만 호출하는 방법이 있습니까? – antonanton
@antonanton 당신은'get_field ('images')'를 사용하여 루프를 실행 했습니까? ACF가 각 객체에 대한 이미지 객체를 반환하도록 설정되어 있다면,'id'가'$ image [ 'id']'와 같이 끝나야합니다. 그렇지 않다면, 루프 안에서'print_r ($ image)'를 실행하면 어떻게됩니까? –
아아, 나는 완전히 잘 풀어 냈다. 고맙습니다! – antonanton