【问题标题】:PHP display an ACF post which has different fields to its sibling postsPHP 显示一个 ACF 帖子,该帖子与其兄弟帖子具有不同的字段
【发布时间】:2015-08-31 13:36:09
【问题描述】:

我有 5 个画廊,它们是使用高级自定义字段中的自定义帖子类型创建的。我的一个画廊与其他画廊有一组不同的字段。这样做的原因是我需要显示一个图像并描述该图像(并重复几个图像)。我对每张图片都使用了Repeater 字段。

显示我的其他画廊的代码,其中包含所见即所得和画廊字段,如下所示:

    if ( have_posts() ) while ( have_posts() ) : the_post(); 
      echo get_the_title();
      echo get_the_content(); 

      //Display images from Gallery Field
      $images = get_field('gallery_images');
          if( $images ): 
              foreach( $images as $image ): 
                  echo $image['url']; 
              endforeach; 
          endif;

如何根据个人帖子名称或 slug(即相册)显示我的特殊画廊的字段

我的转发器字段称为album_information,它的子字段是“album_title”、“album_image”和“album_description”。

非常感谢任何帮助:)

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    http://www.advancedcustomfields.com/resources/repeater/#template-usage

    在你的情况下:

    if( have_rows('album_information') ) {
        while ( have_rows('album_information') ) {
            the_row();
            the_sub_field('album_title');
            the_sub_field('album_image');
            the_sub_field('album_description');
        }
    }
    

    【讨论】:

    • 非常感谢您的回复。正如你回答的那样,我已经弄清楚了这一点。我还需要事先准备以下内容: $args = array( 'post_type' => 'post_type_gallery', 'p' => '1748', //id of the post ); $the_query = new WP_Query($args);
    猜你喜欢
    • 2018-01-10
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 2019-04-06
    • 2020-06-17
    • 2012-05-02
    • 1970-01-01
    • 2016-11-04
    相关资源
    最近更新 更多