我创建了名为“产品”的高级内容类型 POD。POD 具有将图像上传到图库的关系文件字段:字段名称为“图库”。产品在同一个“产品”窗格中相互关联。我想在前端显示相关领域的图像。到目前为止,我没有将以下代码放入 PODS 模板中:
<?php$related = $obj->field( 'related_products' );
if ( ! empty( $related ) && is_array($related) ) {
foreach ( $related as $rel ) {
$id = $rel[ 'id' ];
$name = $rel[ 'name' ];
$permalink = $rel[ 'permalink' ];
$photos=$rel['gallery'];
if ( ! empty( $photos ) && is_array($photos) ) {
foreach ( $photos as $photo ) {
echo wp_get_attachment_image($photo['ID'], 'thumbnail');
} //end of foreach
}; //endif ! empty ( $photos )
echo '<a href="'.site_url( trailingslashit( 'products' ) . $rel[ 'permalink' ] ).'"><h4>' .$name.'</h4></a>';
} //end of foreach
} //endif ! empty ( $related )
?>