2

我已经使用 Wordpress 作为我的 CMS 建立了一个网站。我使用该网站作为作品集来展示我的前端 Web 开发技能,并在该网站的另一个区域开设博客。我通过将帖子归类为项目或博客来解决在网站上有 2 个博客的问题。

我网站的首页包含缩略图和最近项目的链接。当您单击通过时,您将进入使用 Single.php 显示单个帖子的项目详细信息页面。TwentyTen 主题(我已经编辑过)带有分页功能,因此当您在“项目详细信息”页面上时,您还可以单击下一篇或上一篇文章。但是,该类别似乎没有任何限制,因此您也可以点击进入博客文章。我希望用户只能点击进入其他项目。

我已经搜索了这个问题,似乎找到了使用自定义查询的建议,但建议的解决方案似乎都不起作用。

我只想在 Single.php 上一次显示一篇文章,并有分页,让我可以链接到下一个或上一个项目帖子。

有任何想法吗?

4

2 回答 2

3

查看这些链接: http: //codex.wordpress.org/Function_Reference/previous_post_link http://codex.wordpress.org/Function_Reference/next_post_link

这是一个示例,说明如何使用该函数将帖子限制为仅当前 cat 中的帖子:

<?php previous_post_link('%link', 'Next: %title &raquo;' , in_same_cat, 'excluded_categories '); ?>
<?php next_post_link('%link', '&laquo; Previous: %title', in_same_cat, 'excluded_categories '); ?>
于 2011-11-23T23:29:11.527 回答
1

你会想要这样的东西:

$the_page = get_query_var('paged'); //<!-- tell wordpress this is paged
query_posts('cat=7&posts_per_page=6&paged='.$the_page); //<-- set cat= to the numeric category

if (have_posts()) {
    while (have_posts()) {
        the_post();

        // do your awesome WP loop stuff here
        <div><?php next_posts_link('Next Page &raquo;') ?></div>
        <div><?php previous_posts_link('&laquo; Previous Page') ?></div>
    }
}

希望这可以帮助

于 2011-11-21T22:53:41.627 回答