我正在尝试向我的wordpress帖子添加下一个/上一个链接。这是它的代码:
<div id="demo">
<?php
$the_query = new WP_Query( array(
\'category_name\' => \'Case Study\',
\'posts_per_page\' => 1,
));
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<div class="nav-previous alignleft"><?php next_post_link(\'« %link\', \'%title\', TRUE); ?></div>
<div class="nav-next alignright"><?php previous_post_link(\'« %link\', \'%title\', TRUE); ?></div>
<?php else : ?>
<p><?php __(\'No News\'); ?></p>
<?php endif; ?>
</div>
但是,这不起作用,并且不会显示下一个/上一个链接。知道我做错了什么吗?
SO网友:BlueSuiter
我对你的代码做了一些更新。请尝试此更新版本。
<div id="demo">
<?php
$wp_query = new WP_Query( array(
\'category_name\' => \'Case Study\',
\'posts_per_page\' => 1,
));
?>
<?php if ( $wp_query->have_posts() ) : ?>
<?php while ( $wp_query->have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<div class="nav-previous alignleft"><?php next_post_link(\'« %link\', \'%title\', TRUE); ?></div>
<div class="nav-next alignright"><?php previous_post_link(\'« %link\', \'%title\', TRUE); ?></div>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php __(\'No News\'); ?></p>
<?php endif; ?>
</div>