简体   繁体   English

如何根据链接在页面上显示ACF中的WP自定义字段

[英]How to display a WP custom field from ACF on a page depending on the link

I will try to explain my problem simply and quickly: 我将尝试简单快速地解释我的问题:

I used CPT UI in Wordpress to create my own type of posts - employees. 我在Wordpress中使用CPT UI来创建我自己的帖子类型-员工。 Each employee has an ACF field: email, name, description. 每个员工都有一个ACF字段:电子邮件,姓名,描述。 On the team of employees page, I display all people with e-mail, photo and name. 在员工团队页面上,我显示所有带有电子邮件,照片和姓名的人。 Each person is in a box, which is a link to separate subpages. 每个人都在一个框内,该框是指向单独的子页面的链接。

Each sub-page should contain an additional description of the selected employee. 每个子页面均应包含所选雇员的其他说明。

I can't create a link from the team page that will open the subpage of the person you clicked on. 我无法从团队页面创建链接,该链接将打开您单击的人员的子页面。

On the team page ( # is the link to subpage of employee): 在团队页面上(#是员工子页面的链接):

<?php $count = 1; ?>
          <?php $loop = new WP_Query( array( 'post_type' => 'team', 'orderby' => 'post_id', 'order' => 'ASC' ) ); ?>
          <?php while( $loop->have_posts() ) : $loop->the_post();  ?>
            <div class="col-lg-3 col-sm-6">
              <a href="#" id="person-<?php echo $count; ?>" class="team-item">
                  <img src="<?php the_field('team_photo'); ?>">
                  <p><?php the_title(); ?></p>
                  <p><?php the_field('stanowisko'); ?></p>
                  <p><?php the_field('adres_email'); ?></p>
                  <p></p>
                </a>
            </div>
            <?php $count++; ?>
          <?php endwhile; ?>

Of course, the subpage is a template called page-person.php 当然,子页面是一个名为page-person.php的模板。

I tried to send the post ID of the box, which is currently clicked, to page-person.php, but I do something wrong in the link design: 我试图将当前被单击的框的帖子ID发送到page-person.php,但是在链接设计中我做错了:

<a href="<?php bloginfo('stylesheet_directory'); ?>/page-person?post_id=<?php the_ID(); ?>" id="person-<?php echo $count; ?>" class="team-item">

after clicking on the box I get an error in the line: get_header (); 单击框后,我在一行中得到一个错误:get_header(); the subpage file. 子页面文件。

Fatal error: Uncaught Error: Call to undefined function get_header() in 

It seems that you're over complicating it, so you have a custom post type of which is a member of staff meaning each staff is a single post. 看来您已经太复杂了,所以您有一个自定义职位类型,该类型是职员成员,这意味着每个职员都是一个职位。 This means each post has its own URL. 这意味着每个帖子都有自己的URL。 Just put that URL as the href link using the_permalink: 只需使用the_permalink将URL作为href链接:

<a href="<?php the_permalink();?>" id="person-<?php echo $count; ?>" class="team-item">

And then for the template, just make sure your code for individual profiles is used in that custom post types template file. 然后对于模板,只需确保在该自定义帖子类型模板文件中使用了个人资料的代码。 Job done. 任务完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM