[英]display oldest posts in a blog page php
I want to have a blog page which contains 4 posts, the user can see the other posts when he press the link "older posts", but I can't make this work.我想要一个包含 4 个帖子的博客页面,用户可以在按下“旧帖子”链接时看到其他帖子,但我无法完成这项工作。 When I press the link it directs to a blank page.
当我按下链接时,它会指向一个空白页面。
<?php
$args = array( 'numberposts' => 4);
$posts= get_posts( $args );
if ($posts) {
foreach ( $posts as $post ) { ?>
<article>
<header>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</header>
<footer>
<p><?php the_time('j F Y'); ?>
<!-- <br>Publié par <?php the_author_meta('display_name', 1); ?></p> -->
</footer>
<div>
<?php //echo catch_content_image($post->post_content) ?>
<?php the_excerpt() ?>
<a href="<?php the_permalink(); ?>">Suite de l'article</a>
</div>
</article>
<?php
}
}
?>
<nav>
<ul>
<li class="older"><a href="blog-2.html">← Articles précédents</a></li>
</ul>
</nav>
I believe your issue is this line.我相信你的问题是这条线。
<li class="older"><a href="blog-2.html">← Articles précédents</a></li>
Try using something like this instead:尝试使用这样的东西:
$prev = get_previous_posts_link();
echo $prev;
or to go forward或前进
echo get_next_posts_link('Go to next page',4);
You could get more information on that here: https://codex.wordpress.org/Function_Reference/get_next_posts_link您可以在此处获得更多信息: https : //codex.wordpress.org/Function_Reference/get_next_posts_link
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.