链接wordpress中的帖子

时间:2010-08-05 19:08:09

标签: php wordpress pagination hyperlink

我正在尝试链接wordpress中的帖子。让我详细说明一下。在wordpress中,您可以设置要在页面上显示的帖子数量。例如,如果您将该数字设置为1,并且您有10个帖子,那么您将有10个页面。

我在index.php(主帖子页面)上有以下代码。它显示了旧帖子的链接。以下是代码:

    <ul id="postNavigation">
    <li class="floatLeft"><?php next_posts_link('Old posts &raquo;') ?></li>
    <li class="floatRight"><?php previous_posts_link('&laquo; New posts') ?></li>
</ul>

现在,我设置wordpress的方式,我有另一个页面,我使用此代码显示具有特定类别的帖子(此代码在我的page.php文件中):

   <?php if ( is_page('newspaper') ) { // BEGINNING of newspaper page
    ?>
<?php $my_query = new WP_Query('category_name=newspaper'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="post">
    <!--<h3><?php the_title(); ?></h3>-->
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    <div class="clear"></div>
    </div>
    <?php endwhile; ?>

    <ul id="postNavigation">
        <li class="floatLeft"><?php next_posts_link('Old Posts &raquo;') ?></li>
        <li class="floatRight"><?php previous_posts_link('&laquo; New Posts') ?></li>
    </ul>

    <?php } //END of newspaper page
    ?>

但是,它没有显示那里的“旧帖子”链接。有没有人知道这是否以及如何实现?

谢谢, 阿米特

1 个答案:

答案 0 :(得分:1)

我认为较旧的下一个帖子链接是唯一丢失的链接。这意味着您的新帖子链接可见。你如何整理你的帖子?也许你正在查看最老的帖子,所以没有旧帖子显示?

<?php $my_query = 
     new WP_Query('category_name=newspaper&orderby=date&order=desc');?>

这将整理从最新到最旧的帖子,并应启用旧帖子的链接。您也可以尝试使用orderby = ID来使用帖子ID代替日期

相关问题