高级自定义字段colorpicker术语背景css

时间:2017-09-09 05:56:44

标签: php wordpress advanced-custom-fields

我使用自定义字段colorpicker进行类别(高级custon字段插件)。当我在块中粘贴字段时,它会读取十六进制颜色,但是当我在页面内部使用它时,它不会获得该术语,尽管它应该捕获数据(根据其他问题中的教程和答案)。这就是我在single.php中所拥有的:

<style type="text/css">
    .event-category-color {
        background-color: <?php the_field('events_coloropicker', $term); ?>;
    }
</style>
<div style="background-color:<?php the_field('events_coloropicker', $term); ?>">Something here...</div>
<div class="event-category-color" >
    <?php the_field('events_coloropicker', $term ); ?>
</div>

最后一个块获得十六进制颜色,其他没有...

UPD:这是我对single.php的全部内容:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="main-event-content">
    <header class="entry-header">
        <div class="">
            <div class="post-img">
                <?php
                    if ( has_post_thumbnail() ) { the_post_thumbnail( 'full' ); }
                ?>
            </div>
        </div>
        <div class="category-style">
            <style type="text/css">
                .event-category-color {
                  background-color: <?php the_field('events_coloropicker', $term); ?>;
                  padding: 20px;
                  margin: 0 auto;
                  max-width: 600px;
                  height:160px;
                }

            </style>
            <div style="background-color:<?php the_field('events_coloropicker', $term); ?>">Something here...</div>
            <div class="event-category-color <?php the_field('events_coloropicker', $term ); ?>" >
                <?php the_field('events_coloropicker', $term ); ?>
            </div>
            <div class="track-info">
                <div class="event-title">
                    <?php
                        if ( is_singular() ) :
                            the_title( '<h1 class="entry-title">', '</h1>' );
                        else :
                            the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
                        endif;

                        if ( 'post' === get_post_type() ) : ?>
                    <?php
                    endif; ?>
                </div>
                <ul>
                    <li>Breadcrumbs</li>
                    <?php if( get_field('start_date') ): ?>
                        <li><strong><?php the_field('start_date'); ?></strong></li>
                    <?php endif; ?>
                    <?php if ( get_field( 'start_time' ) ): ?>
                        <li><?php the_field('start_time'); ?><?php if ( get_field( 'end_time' ) ): ?> - <?php the_field('end_time'); ?></li><?php endif; ?>
                    <?php endif; ?>
                    <li>Location: <?php echo $location['address']; ?></li>
                    <?php if( get_field('screening_format') ): ?>
                        <li>Screening Format: <?php the_field('screening_format'); ?></li>
                    <?php endif; ?>
                    <?php if( get_field('event_director') ): ?>
                        <li>Director: <strong><?php the_field('event_director'); ?></strong></li>
                    <?php endif; ?>
                    <li class="category-name">
                        <?php $terms = get_the_terms( get_the_ID(), 'event_categories'); if(!empty($terms)) {$term = array_pop($terms); $custom_field = get_field('events_coloropicker', $term ); echo $custom_field; } ?>
                    </li>
                </ul>
            </div>
            <div class="category-description">
                <?php 
                 $terms = get_the_terms( $post->ID , 'event_categories' );
                 if ( $terms != null ){
                 foreach( $terms as $term ) {
                 print $term->description ;
                 unset($term);
                }} ?>
            </div>

        </div>
    </header><!-- .entry-header -->
</div>

<div class="some_more_content">
    <?php
        the_content();
    ?>
</div>
<div class="entry-content">
    <div class="main-event-text"><?php the_field('event_description'); ?></div>
</div>

工作更新:

<div class="event-category-color">Colorful block
                    <?php $terms = get_the_terms( get_the_ID(), 'event_categories'); 
                        if(!empty($terms)) {
                            $term = array_pop($terms); 
                            $custom_field = get_field('events_coloropicker', $term ); 
                    }?>
                    <style type="text/css">
                        .event-category-color {
                          background-color: <?php the_field('events_coloropicker', $term); ?>;
                        }
                    </style>
                </div>

0 个答案:

没有答案