我有一个WordPress网站,我想显示当前类别中的所有帖子的列表(除了当前的帖子)。
我需要使用名为"test“的特定custom-field的值作为锚文本,而不是post标题。
我如何编辑下面的代码来做到这一点,并排除当前的帖子?
<?php
global $post;
$categories = get_the_category();
foreach ($categories as $category) :?>
<ul>
<?php
$posts = get_posts('numberposts=3&category='. $category->term_id);
foreach($posts as $post) : ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a> </li>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>发布于 2015-10-06 20:18:50
这样做可能会奏效:
<?php
global $post;
$categories = get_the_category();
$currentID = get_the_ID();
foreach ($categories as $category) :?>
<ul>
<?php
$posts = get_posts('numberposts=3&category='. $category->term_id);
foreach($posts as $post) :
if ( $currentID != $post->ID ) {
?>
$test_value = get_post_meta( $post->ID, 'test', true );
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php if ( ! empty( $test_value ) ) {echo $test_value; } else { echo 'Nothing'; } ?>
</a>
</li><?php
} ?>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>https://stackoverflow.com/questions/32978485
复制相似问题