首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP Wordpress ACF页面链接

PHP Wordpress ACF页面链接
EN

Stack Overflow用户
提问于 2015-08-11 01:20:35
回答 2查看 2.6K关注 0票数 0

我正在尝试使用ACF (高级自定义字段)插件中继器字段链接到其他wordpress页面。我的front_page.php中有以下代码:

代码语言:javascript
复制
// 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,因为我接管了一个网站的设计师谁离开了公司-现在我是唯一的设计师!提前感谢您的帮助!

EN

回答 2

Stack Overflow用户

发布于 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' ) )

票数 0
EN

Stack Overflow用户

发布于 2018-03-07 18:11:21

修复方法如下:

代码语言:javascript
复制
<?php echo $link[url]; ?>

链接是作为数组工作的,因为你可以使用它的标题等。我希望它能对你有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31925524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档