将 ACF 字段添加到 post 元

Adding ACF field to post meta

我找到了控制我需要编辑的帖子的代码:

$img = ( $mode == 'top' ) ? get_the_post_thumbnail( null, 'large' ) : get_the_post_thumbnail( null, 'medium' );

    $the_image = sprintf( '<span class="c_img">%s</span>', $img );

    $thumb_link = sprintf( '<a class="%s" href="%s" rel="bookmark" title="%s %s" style="%s">%s</a>', $classes, get_permalink( $post ), __( 'Link To', 'pagelines' ), the_title_attribute( array( 'echo' => false ) ), $style, $the_image );

    $output = ( 'top' == $mode ) ? sprintf( '<div class="full_img fix">%s</div>', $thumb_link ) : $thumb_link;

    return apply_filters( 'pagelines_thumb_markup', $output, $mode, $format );

}

输出如下:

<span class="c_img"><img src="example image"></span>

我需要在跨度内插入我的自定义 ACF(高级自定义字段)。 ACF 字段名称是 parent_category 所以它可能是这样的:

<span class="c_img"><i class="cat_tag">Deep House</i><img src="example image"></span>

所以我需要在两者之间注入这个:

<i class="cat_tag"><?php the_field('parent_category'); ?></i>

我怎样才能做到这一点?

下面我把相关的部分粘起来了。请注意我的评论,它会告诉您要更改的内容/要添加的内容:

$img = ( $mode == 'top' ) ? get_the_post_thumbnail( null, 'large' ) : get_the_post_thumbnail( null, 'medium' );

    // Add this line....(gets the markup you requested, and custom field value)
    $custom_field = '<i class="cat_tag">' . the_field('parent_category') . '</i>';
    // And modify this line.... (inserts it into the returned string)
    $the_image = sprintf( '<span class="c_img">%s%s</span>', $custom_field, $img );

    $thumb_link = sprintf( '<a class="%s" href="%s" rel="bookmark" title="%s %s" style="%s">%s</a>', $classes, get_permalink( $post ), __( 'Link To', 'pagelines' ), the_title_attribute( array( 'echo' => false ) ), $style, $the_image );

    $output = ( 'top' == $mode ) ? sprintf( '<div class="full_img fix">%s</div>', $custom_field, $thumb_link ) : $thumb_link;

    return apply_filters( 'pagelines_thumb_markup', $output, $mode, $format );