ACF将CPT字段添加到标头

时间:2018-01-09 19:20:19

标签: php wordpress advanced-custom-fields

我有一个名为'Projects'的自定义帖子类型,我已经为我的single-projects.php添加了灵活的字段内容。我正在尝试为主要header.php中的每个项目添加一个英雄图像,因为我希望我的英雄图像位于导航后面。我有一切正常,但我的英雄形象显示在CPT存档页面和CPT单页面上,但我只是想在每个项目页面上显示英雄形象。

在我的header.php文件中我有:

<?php

  // check if the flexible content field has rows of data
  if( have_rows('project_flexible') ):

  // loop through the rows of data
  while ( have_rows('project_flexible') ) : the_row();

    if( get_row_layout() == 'project_hero_image'):
      $hero_image = get_sub_field('image'); ?>

    <div class="hero-image"><img src="<?php echo $hero_image; ?>">
    </div>

    <?php
      endif;
      endwhile;

      else :
       // no layouts found
      endif;
    ?>

1 个答案:

答案 0 :(得分:0)

也许您可以尝试将其仅显示在单页上:

select listagg(chr(fw_char2)) within group(order by lvl) 
from
  (select rid, lvl, 
      CASE WHEN ascii(fw_char) between 15711328 and 15712174 
           THEN ascii(fw_char)-15711328
           ELSE ascii(fw_char) 
      END as fw_char2
   from 
      (select my_table.rowid as rid, 
              substr(full_width_num, lvl, 1) as fw_char, 
              lvl
        from my_table
        join (select level as lvl from dual connect by level <= 4000) 
            on lvl <= length(full_width_num)
      ) splitfield
   )
group by rid
;