我正在尝试使用ACF (高级自定义字段)插件中继器字段链接到其他wordpress页面。我的front_page.php中有以下代码:
// Product Grid Repeater
$grid = get_post_meta( get_the_ID(), 'product_grid', true );
// Check if acf/custom field data exists
if( $grid ) {
?>
<div class="product-grid text-center">
<h3>Our Product Lineup</h3>
<ul id="productgrid" class="large-block-grid-4 medium-block-grid-2 small-block-grid-2 effect-2" data-equalizer>
<?php
// loop through the rows of data
for( $i = 0; $i < $grid; $i++ ) { // Custom Count/Loop through rows
// Important: Notice the _preceding and trailing_ underscores
// for $hero_image Set image return value to array and use a variable to test if photon works by using echo $image['url']
$image = (int) get_post_meta( get_the_ID(), 'product_grid_' . $i . '_product_image', true ); // Subfield Name: gallery_slide_image, Type: Image
$name = get_post_meta( get_the_ID(), 'product_grid_' . $i . '_product_name', true ); // Subfield Name: gallery_slide_title, Type: Text
$type = get_post_meta( get_the_ID(), 'product_grid_' . $i . '_product_type', true ); // Subfield Name: gallery_slide_title, Type: Text
$link = esc_html( get_post_meta( get_the_ID(), 'product_grid_' . $i . '_product_link', true ) ); // Subfield Name: gallery_slide_link, Type: Page Link
?>
<li>
<a href="<?php echo $link; ?>">
<div class="grid-outline" data-equalizer-watch>
<div class="product-grid-img-wrap">
<?php echo wp_get_attachment_image( $image, 'full' ); ?>
</div>
<span class="type"><?php echo $type ?></span>
</div>
</a>
</li>
<?php
} // CLOSE for
?>
</ul>
</div>
<?php
} //CLOSE if( $grid )但当我点击这些链接时,它们会转到它们的ID,而不是URL/固定链接。我有一种感觉,它是在$link = esc_html( get_post_meta( get_the_ID(), 'product_grid_' . $i . '_product_link', true ) ); // Subfield Name: gallery_slide_link, Type: Page Link部分,但我真的不确定要将其更改为什么。
我不知道PHP,因为我接管了一个网站的设计师谁离开了公司-现在我是唯一的设计师!提前感谢您的帮助!
发布于 2016-05-30 07:07:51
这个问题很老了,我从一些"ACF页面链接“谷歌搜索中寻找不同的问题,只是想在这里添加一个提示。
首先,Page Link字段将页面/帖子ID存储在wp_postmeta表中,因此当您使用原生wp函数时,您将始终获得ID,而不是您所期望的get_post_meta()。如果你使用ACF函数get_field(),你会得到网址。
因此,解决方案是要么使用get_field(),要么完全使用WordPress-way并使用get_permalink( get_post_meta( 'field_name' ) )。
发布于 2018-03-07 18:11:21
修复方法如下:
<?php echo $link[url]; ?>链接是作为数组工作的,因为你可以使用它的标题等。我希望它能对你有所帮助。
https://stackoverflow.com/questions/31925524
复制相似问题