user7190475
user7190475

Reputation:

Pagebreak using wp_link_pages in Wordpress

I have a php script that reads a text file of 10000 urls one in each line. The script displays all the urls in a blog post. I want the page to be divided into 10 small pages to facilitate comfortabe browsing. So how to add a pagebreak using <?php wp_link_pages(); ?> function inside a post? Something like this:

<?php
echo "Hi, This is First Page";

wp_link_pages();  

echo "Hi, This is Second Page";
?>

Upvotes: 1

Views: 610

Answers (3)

MikeyMo
MikeyMo

Reputation: 105

This works just fine:

global $post;
$total = substr_count($post->post_content, '<!--nextpage-->') + 1;

Upvotes: 0

vico
vico

Reputation: 2142

That isn't how wp_link_pages(); works. It only displays your the_content in pages if your the_content contains this tag <!--nextpage-->

sudo code

<?php
echo apply_filter ("the_content" , "Hi, This is First Page<!--nextpage-->Hi, This is second Page");
wp_link_pages(); 
?>

You might want to check out this question as to how to retain the page data if you are creating your own page content and not using the standard content area.

Wordpress PHP - need to retain nextpage paginating tag in custom query

Upvotes: 1

Laoujin
Laoujin

Reputation: 10229

When already in a php block, you can execute a function without opening another php block. According to the documentation, wp_link_pages(); should also be called without echo.

wp_link_pages();

Documentation:
https://codex.wordpress.org/Function_Reference/wp_link_pages

Upvotes: 0

Related Questions