1
我想顯示在我的單一職位視圖下的3個職位(我有自定義職位類型設置,所以希望此查詢工作在所有單個帖子頁面不管帖子類型如何)。WordPress的 - 顯示3相關的職位,無論職位類型,自定義或其他
但是,下面的代碼,我沒有得到任何相關的職位顯示。當我刪除.
我得到3相關帖子顯示,但與當前職位是其中之一。因此,爲什麼我添加'排除',但我不明白爲什麼它不顯示任何時候我添加此。
'&exclude=' . $current
任何幫助將不勝感激。 感謝
<?php
$backup = $post;
$current = $post->ID; //current page ID
global $post;
$thisPost = get_post_type(); //current custom post
$myposts = get_posts('numberposts=3&order=DESC&orderby=ID&post_type=' . $thisPost .
'&exclude=' . $current);
$check = count($myposts);
if ($check > 1) { ?>
<h1 id="recent">Related</h1>
<div id="related" class="group">
<ul class="group">
<?php
foreach($myposts as $post) :
setup_postdata($post);
?>
<li>
<a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark">
<article>
<h1 class="entry-title"><?php the_title() ?></h1>
<div class="name-date"><?php the_time('F j, Y'); ?></div>
<div class="theExcerpt"><?php the_excerpt(); ?></div>
</article>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php
$post = $backup;
wp_reset_query();
?>
</div><!-- #related -->
<?php } ?>
完美 - 謝謝@icethrill – fidev 2013-04-25 13:54:20
沒問題,很高興能夠幫助! – MrZiggyStardust 2013-04-25 13:56:25