【问题标题】:Link Genres in Advanced Custom Fields高级自定义字段中的链接类型
【发布时间】:2023-03-13 17:45:01
【问题描述】:

我正在使用高级自定义字段。我想链接类型自定义字段的值(例如惊悚片,悬念等),以便当用户单击其中一个值时,他们将获得过滤后的帖子列表。例如。当他们点击 Thriller 时,他们将获得 Thriller 类别中的所有帖子。

到目前为止,我的 ACF 代码如下:

<!-- Entry Content Start -->
        <article <?php post_class('entry clearfix fitvids'); ?>>
            <div class="inner-post">
                <div class="cover">
                    <div class="post-image">
                        <?php
                            if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                              the_post_thumbnail();
                            }
                        ?>
                    </div>
                    <div class="custom-fields">
                        <?php the_meta(); ?>
                        <div class="ad">
                            <img src="http://lorempixel.com/160/600" alt="">
                        </div>
                    </div>
                </div>
                <div class="the-content">
                   <?php the_content(); // This is your main post content output  ?>
                </div>

            </div><!-- /inner-post -->
        </article><!-- /entry -->

有解决办法吗?

【问题讨论】:

    标签: php wordpress custom-fields


    【解决方案1】:

    您应该使用自定义page template 创建一个页面。在此模板中,您应该根据通过 $_GET 参数传递的自定义字段来拉帖子。
    例如:$movies = get_posts(array('meta_key'=&gt;'your_custom_key', 'meta_value'=&gt;$_GET['genre']));
    然后您应该生成适当的链接来访问此页面,该链接应链接到我们的自定义页面,包括我们$_GET 变量中的流派。例如页面的 slug 是movies。那么我们的链接将具有以下结构:/movies/?genre=custom_field_value.

    【讨论】:

    • 对不起,我不明白这一点。我对 PHP 知之甚少 :(
    • 你可以尝试关注这个guide
    • 我会试试的。。谢谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 2020-08-15
    • 1970-01-01
    • 2018-01-29
    • 2020-04-26
    • 1970-01-01
    • 2017-12-16
    相关资源
    最近更新 更多