【发布时间】:2018-02-19 21:21:37
【问题描述】:
我正在尝试使用高级自定义字段插件并将其与我编写的部分(可能不是正确的词)相关联,该部分将显示来自自定义帖子类型的字段。
如何将 php 文件与自定义帖子类型相关联?
目标是能够在帖子中嵌入部分内容。
这是我的部分:cta-partial.php
<?php
/*
Template Name: CTA-Partial
*/
?>
<!-- cta markup -->
<!-- if there is an article then load -->
<?php
$args = array(
'post_type' => 'cta_post_type'
);
$query = new WP_Query( $args ); ?>
<?php if( $query->have_posts() ) : while( $query->have_posts() ) :
$query->the_post();?>
</div>
</div>
<!-- end the markup so as to allow full-width -->
<div class="article" style="background-image: url('<?php the_field('cta_background'); ?>')">
<div class="custom-background">
<div class="columns small-12 medium-6 image-container">
<div class="hide-for-medium">
<img src="<?php the_field('cta_background'); ?>">
</div>
</div>
<div class="columns small-12 medium-6 mobile-style">
<h1> <?php the_field('cta_title');?></h1>
<p><?php the_field('cta_text'); ?></p>
<a href="<?php the_field('button_link');?>"><button><?php the_field('button_label')?></button></a>
</div>
</div>
</div>
<div class="row">
<div class="columns small-12 medium-12 content-wrapper">
<!-- continue content loop -->
<?php endwhile; endif; wp_reset_postdata(); ?>
这是我要呈现与我的自定义字段帖子类型关联的 php 的文件。
这里是 ACF 的文档:https://www.advancedcustomfields.com/resources/ 我一直在搜索文档,但不确定是否可行。感谢您到目前为止的帮助,仍在研究中。
【问题讨论】:
标签: php wordpress custom-post-type advanced-custom-fields