我创建了wp主题,使用插件自定义帖子类型UI。
创建的节-Customers
和Projects
.
在页面项目中。php,显示所有客户的列表(链接):
$args = array(
\'post_type\' => \'customer\'
);
$the_query = new WP_Query( $args );
我正在尝试显示帖子中的内容
projects
(关于客户)。页
single-customer.php
显示来自的内容
customers
, 但我需要来自
projects
.
如何获取此帖子内容?有可能吗?
UPD
代码输入
single-customer.php
:
`<div class="page-head text-center">
<div class="container">
<h1 class="page-head_title"><?php the_title(); ?></h1>
<p><?php the_subtitle(); ?></p>
</div>
</div>
<?php
// This is for projects posts
$args = array(
\'post_type\' => \'project\'
);
$the_query = new WP_Query( $args );
?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
// loop here
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile;
wp_reset_postdata();
else : ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>`
UPD
如果我使用此代码
<?php acf_form(); ?>
它的显示内容,我需要,但它显示所有的文本区域和输入的wp管理面板。如果我使用
<?php the_field(\'project-sections\'); ?>
- its显示器
Array, Array, Array, Array
最合适的回答,由SO网友:siberian 整理而成
我找到了解决方案:
<?php if( have_rows(\'project-sections\') ): ?>
<?php $i = 0; ?>
<?php while( have_rows(\'project-sections\') ): the_row(); ?>
<section class="<?php if ($i % 2 == 0) : ?>bg-gray<?php else: ?>bg-white<?php endif; ?>">
<div class="container">
<h2 class="page-head_sub-title"><?php the_sub_field(\'project-sections-title\'); ?></h2>
<?php the_sub_field(\'project-sections-description\'); ?>
</div>
</section>
<?php $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
需要使用
<?php the_sub_field(\'name-sub-field\'); ?>
在…内
<?php while( have_rows(\'name-field\') ): the_row(); ?>
SO网友:Ronald
同一页中有多个循环
<?php
// this is for customer posts
$args = array(
\'post_type\' => \'customer\'
);
$the_query = new WP_Query( $args );
?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php // loop here
the_title();
the_content(); ?>
<?php endwhile;
wp_reset_postdata();
else : ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>
<?php
// This is for projects posts
$args = array(
\'post_type\' => \'projects\'
);
$the_query = new WP_Query( $args );
?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php // loop here
the_title();
the_content(); ?>
<?php endwhile;
wp_reset_postdata();
else : ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>
你也可以这样混合帖子
\'post_type\' => array(\'customer\', \'projects\'),