Reputation: 445
I have blog which is in sub directory and showing last post on static index page on main site.
main site -> http://example.com blog -> http://example.com/wp
The blog post is showed correctly on main site but I can't show links for prev and next post/article. This is what I have an what I'm trying
<?php
define('WP_USE_THEMES', false);
require('wp/wp-blog-header.php');
$posts = get_posts('numberposts=1&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<h1><?php the_title(); ?>
</h1><h2><?php the_date(); echo "<br />";?></h2>
<h3><?php the_content(); ?> </h3>
<div class="navigation"><p><?php posts_nav_link(); ?></p></div>
<?php endforeach; ?>
So this isn't visible: <div class="navigation"><p><?php posts_nav_link(); ?></p></div>
Upvotes: 0
Views: 2198
Reputation: 429
In Layman language it is a wordpress function to fetch posts/custom-posts. Internally it calls WP_Query function. Or you can use WP_Query instead of this. 'posts_nav_link' function does not work with WP_Query & get_posts function. You can try this to get next previous links.
$posts = get_posts('numberposts=1&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<h1><?php the_title(); ?>
</h1><h2><?php the_date(); echo "<br />";?></h2>
<h3><?php the_content(); ?> </h3>
<?php endforeach; ?>
<div class="navigation">
<p><?php previous_post_link(); ?><?php next_post_link(); ?></p>
</div>
Upvotes: 2
Reputation: 268
I cant comment you because I haven't enough reputations, First follow https://codex.wordpress.org/Template_Tags/get_posts link then check the sample code.
and also check the post display setting in the wp-admin panel /wp-admin/options-reading.php settings->reading section.
Upvotes: 2