WordPress,自定义页面主题下一篇/上一篇文章
我有一个带有代码的自定义页面模板:
<?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('← %link') ?></span>
<span class="next"><?php next_post_link('%link →') ?></span>
</div>
<div class="clear whitespace"></div>
<?php else : ?>
<div class="navigation">
<div class="previous"><?php next_posts_link('← Previous Entries') ?></div>
<div class="next"><?php previous_posts_link('Next Entries →') ?></div>
</div>
<div class="clear flat"></div>
<?php endif; ?>
我已将每页的最大帖子数设置为 5,但是使用此主题模板的页面不会显示链接。有什么想法吗?我可以使用什么代码来获取它们。
谢谢
I have a custom page template with code:
<?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(); ?>
The navigation.php file has the previous / next code (it works fine for the standard post pages and archive pages)
navigation.php:
<?php if (is_single()) : ?>
<div class="navigation">
<span class="previous"><?php previous_post_link('← %link') ?></span>
<span class="next"><?php next_post_link('%link →') ?></span>
</div>
<div class="clear whitespace"></div>
<?php else : ?>
<div class="navigation">
<div class="previous"><?php next_posts_link('← Previous Entries') ?></div>
<div class="next"><?php previous_posts_link('Next Entries →') ?></div>
</div>
<div class="clear flat"></div>
<?php endif; ?>
I have set the maximum posts per page to 5, but the page using this theme template wont show the links. Any ideas? What code can i use to get them.
Thankyou
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
previous_post_link 和 next_post_link 等对页面没有任何意义。页面不按日期和时间排序,它们是分层的。换句话说,没有“下一个”页面。从这方面来说,这没有任何意义。
您的基本问题是您正在使用自定义页面模板来显示特定类别的帖子。这是错误的做法,WordPress 已经拥有完全有效的类别档案,它工作正常并且期望正确显示帖子。
长话短说:您永远无法让页面模板方法 100% 正确运行。事实并非如此。帖子从来就不是要显示在页面上的,尝试这样做只会导致事情不起作用。
previous_post_link and next_post_link and the like don't make any sense for Pages. Pages are not ordered by date and time, they are hierarchical. In other words, there is no "next" Page. That doesn't make any sense in that respect.
Your base problem is that you're using a custom Page template to display Posts from a specific Category. This is the wrong way to do it, WordPress has perfectly valid category archives already, which work fine and which expect to display Posts properly.
Long story short: You will never get your Page Template approach to work 100% correctly. It just doesn't work that way. Posts were never meant to be displayed on Pages, and trying to do so only leads to things not working.