【发布时间】:2015-05-14 13:38:56
【问题描述】:
我正在使用 acf wordpress 插件将布尔字段 (featured_project) 添加到自定义帖子(项目)。
我正在尝试对分类存档页面上的帖子进行排序,以显示顶部有特色的帖子和底部没有特色的帖子。
同一类型的帖子有多个类别。
我已经阅读了一些其他类似的问题,其中的解决方案是使用 'wp_query' 或 pre_get_posts,但我似乎无法让它工作。
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ( get_field('featured_project') ) { ?>
<article class='project featured' id="post-<?php the_ID(); ?>" <?php post_class( 'cf' ); ?> role="article">
<a href='<?php the_permalink(); ?>'>
<h3 class="h2"><?php the_title(); ?></h3>
<?php
$url = wp_get_attachment_url( get_post_thumbnail_id() );
$width = 300;
$height = 200;
$crop = true;
$retina = false;
// Call the resizing function (returns an array)
$image = matthewruddy_image_resize( $url, $width, $height, $crop, $retina );
?>
<img src='<?php echo $image['url']; ?>'/ alt='<?php the_title(); ?>'>
</a>
<?php // the_post_thumbnail( 'projects-full', false ); ?>
<div class='excerpt'><?php the_excerpt(); ?></div>
</article>
<?php } else { ?>
是分类文件中代码的一部分。
谢谢
更新:还没有找到解决方案,其他人可以加入吗?
【问题讨论】:
-
你试过查看 get_field('featured_project') 的值吗?
-
是的,但我看到的唯一方法是在循环内,或者在循环外传递帖子 ID。
-
是的,但你确定你的
if语句正在工作就是我所说的,你想让 get_field... 返回 true 或 1,它会给你吗? -
啊,抱歉,是的,我得到每个帖子的预期 1 或 0。
-
好的,你有打印的东西,只是顺序不对?
标签: php wordpress advanced-custom-fields