【发布时间】:2013-10-16 01:06:03
【问题描述】:
我希望我的主页显示我的最新帖子,这些帖子是我的投资组合项目。在这些项目缩略图下,我有我的静态内容,我正在使用来自 Advanced Custom Fields 的 Repeater 插件来抓取这些内容。我不能让它在同一个页面上工作......要么让博客工作,要么让 ACF 的东西工作。永远不要同时使用,因为一个需要是指定的静态页面,一个需要是帖子页面。我不明白如何将它捆绑在一起并使其显示为一页。
我已经尝试过阅读面板中的设置..
我试过使用front-page.php
我已经阅读了 WP 层次结构等
我试过使用模板...
我试过wp_reset_postdata();,我在 Stack Overflow 的其他地方读到过。
我必须在阅读面板中使用哪些设置。我需要使用模板文件吗?
这是我正在使用的代码,我已经在模板和不同文件之间拆分了代码,但只是为了便于在这里阅读它们(也许这是正确的方法,我不会知道..)
<!-- The posts/portfolio items -->
<?php get_header(); ?>
<div>
<?php if(have_posts()) : ?>
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<!-- Permalink,title and post thumbnail here (omitted) -->
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<h2>No Posts found</h2>
<?php endif; ?>
</div>
<!-- Now for the ACF Stuff -->
<?php if(get_field('care_list')): ?>
<?php while(has_sub_field('care_list')): ?>
<div class="grid_2 what-i-care-about gap">
<div class="important-img-container">
<?php the_sub_field('care_list_image'); ?>
</div>
<h3><?php the_sub_field('care_list_title'); ?></h3>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
请帮助沮丧的学习者!提前致谢。
【问题讨论】:
-
好的,我已经修复了它,但我认为它可以改进吗?我将我所有的项目添加到一个名为 Portfolio 的类别中,并将其包含在 if(have_posts) 之前:
<?php query_posts( array ( 'category_name' => 'Portfolio', 'posts_per_page' => -1 ) ); ?>。然后在循环之后我使用了wp_reset_query();。显然,Wordpress 不太推荐这种方式。
标签: wordpress advanced-custom-fields