Wordpress,自定义页面主题下一个/上一篇文章

时间:2010-04-02 16:27:58

标签: wordpress themes

我有一个带代码的自定义页面模板:

<?php 
/*
Template Name: Featured
*/
get_header(); ?>

    <div id="content_box">

        <div id="content" class="posts">
        <img src="http://www.dinneralovestory.com/wp-content/uploads/2010/04/favorites.png" alt="Favourites"/><br clear="all" /><br />

        <?php 
        //The Query
        $my_query = new WP_Query('category_name=favourites');
        if ($my_query -> have_posts()) : 
        ?>

            <?php while ($my_query -> have_posts()) : $my_query -> the_post(); ?>

            <div class="featured_box">
                <div class="featured_thumb">
                    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
                </div>
                <div class="featured_content">
<span class="post_title"><?php the_title(); ?></span>
                    <?php the_excerpt(); ?>
                </div>
            </div>  
<br clear="all" /><br />        

            <?php endwhile; ?>

        <?php include (TEMPLATEPATH . '/navigation.php'); ?>

        <?php else : ?>

            <h2 class="page_header center">Not Found</h2>
            <div class="entry">
                <p class="center">Sorry, but you are looking for something that isn't here.</p>
            </div>

        <?php 
        endif; 
        wp_reset_query();
        ?>

        </div>

        <?php get_sidebar(); ?>

    </div>

<?php get_footer(); ?>

navigation.php文件包含上一个/下一个代码(它适用于标准帖子页面和存档页面)

navigation.php:

<?php if (is_single()) : ?>

<div class="navigation">
    <span class="previous"><?php previous_post_link('&larr; %link') ?></span>
    <span class="next"><?php next_post_link('%link &rarr;') ?></span>
</div>
<div class="clear whitespace"></div>

<?php else : ?>

<div class="navigation">
    <div class="previous"><?php next_posts_link('&larr; Previous Entries') ?></div>
    <div class="next"><?php previous_posts_link('Next Entries &rarr;') ?></div>
</div>
<div class="clear flat"></div>

<?php endif; ?>

我已将每页的最大帖子数设置为5,但使用此主题模板的页面不会显示链接。有任何想法吗?我可以用什么代码来获取它们。

三江源

1 个答案:

答案 0 :(得分:2)

previous_post_link和next_post_link等对Pages没有任何意义。页面不按日期和时间排序,它们是分层的。换句话说,没有“下一页”。在这方面没有任何意义。

您的基本问题是您使用自定义页面模板来显示特定类别的帖子。这是错误的方法,WordPress已经完全有效的类别档案,工作正常,并期望正确显示帖子。

长话短说:您永远不会让您的页面模板方法100%正确地工作。它只是不起作用。邮件从未打算在Pages上显示,并且尝试这样做只会导致无法正常工作。

相关问题