duandi8852752 2017-04-18 13:52
浏览 37

使用if语句从其他页面复制高级自定义字段内容

Im trying to copy some content from another page with an if statement that has an input from advanced custom fields so I dont have to manage two pages with the same content. However the code has a bug in it which prevents the page from loading when this section starts. I guess I made a type somewhere. What could it be?

The first block contains the information from post id 4767 that i want to display on post id 4940. The second block is the information that would normally be loaded and is entered on all the individual pages.

<?php if(is_single('4940')) { 
            if( have_rows('partner', 4767) ):
                while ( have_rows('partner', 4767) ) : the_row();
                    $partnerTag      = get_sub_field('partner_tag', 4767);
                    $partnerName     = get_sub_field('partner_name', 4767);
                    $partnerImage    = get_sub_field('partner_image', 4767);
                    $partnerImageUrl = $partnerImage['sizes']['medium'];
                    $partnerLink     = get_sub_field('link', 4767); 
      } else { 
            if( have_rows('partner') ):
                while ( have_rows('partner') ) : the_row();
                    $partnerTag      = get_sub_field('partner_tag');
                    $partnerName     = get_sub_field('partner_name');
                    $partnerImage    = get_sub_field('partner_image');
                    $partnerImageUrl = $partnerImage['sizes']['medium'];
                    $partnerLink     = get_sub_field('link');
 } ?>

ps. I tried both: is_single('4940') and is_single(4940)

  • 写回答

1条回答 默认 最新

  • douju2014 2017-04-18 13:59
    关注

    You could just check the value of $post->ID directly.

    if( $post->ID == 4940 ) { ... }
    

    Are you within the query? is_single() and is_singular() will not work outside loop.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看