自定义帖子类型下一个/上一个链接?


12

我有一个自定义帖子类型,称为投资组合。我需要一个没有插件的上一个/下一个链接。有人有解决办法吗?

示例帖子:http : //themeforward.com/demo2/archives/portfolio/boat

<?php get_header(); ?>

<!-- Begin wrap -->
<div class="clear">
<div id="full_container">
<div id="content2">
<div id="content">

<!-- Grab posts -->
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>

<!-- Post title -->
<h1>
    <?php the_title(); ?>
</h1>

<!-- The post -->
<?php the_content(); ?>

<!-- Tags -->
<h3 class="tags">
    <?php the_tags('Tags ',' / ','<br />'); ?>
</h3>

<!-- End wrap -->
</div>

<!-- Next/Previous Posts -->
<div class="mp_archive2">
<div id="more_posts">
    <div class="oe">
        <?php previous_post_link('%link', '« Previous post', TRUE); ?>
    </div>

    <div class="re">
        <?php next_post_link('%link', 'Next post »', TRUE); ?>
    </div>
</div>
</div>

<?php endwhile; else: ?>
<p>No matching entries found.</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>

3
为什么讨厌插件?
chrisguitarguy 2011年

因为如果它是插件,则不会内置在主题中。
AndrettiMilas

4
@Lucas Wynne如果要内置它,请将一些插件代码复制/粘贴到您的themes.php文件中。
kaiser

2
@kaiser当然会假设您遵守许可和IP条件,如果要制作要出售的主题,这并不容易。
Phill Healey

Answers:


14

如果您需要单个帖子的下一个/上一个链接,则可以使用内置next_post_link函数和match previous_post_link,这两个函数都应该在循环中使用。

对于档案,请使用next_posts_linkprevious_posts_link

所有这些都可以与自定义帖子类型配合使用。


他们没有用我的主题。
AndrettiMilas

3
好的。好吧,没有看到您的任何代码,很难说出原因。是否有PHP错误或警告?您是否为要获取链接的功能插入了多个帖子?
chrisguitarguy 2011年

我已经在上面更新了我的问题。
AndrettiMilas

尝试使用第三个TRUE参数,让我们知道。
chrisguitarguy 2011年

第三个真实论点?
AndrettiMilas

14
<?php
$prev_post = get_previous_post();
if($prev_post) {
   $prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
   echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" class=" ">&laquo; Previous post<br /><strong>&quot;'. $prev_title . '&quot;</strong></a>' . "\n";
}

$next_post = get_next_post();
if($next_post) {
   $next_title = strip_tags(str_replace('"', '', $next_post->post_title));
   echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '" class=" ">Next post &raquo;<br /><strong>&quot;'. $next_title . '&quot;</strong></a>' . "\n";
}
?>

3
请格式化您的代码/答案并为其添加说明。
Maruti Mohanty

1
无论如何,我可以将其限制为CPT所在的分类法吗?
吉尔·哈默
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.