Title: Multipaging posts from template
Last modified: August 21, 2016

---

# Multipaging posts from template

 *  [nosabesnadacom](https://wordpress.org/support/users/nosabesnadacom/)
 * (@nosabesnadacom)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/multipaging-posts-from-template-1/)
 * Hi, I’ve been trying to manually multipage posts with no result. I explain, instead
   of writting in the post_content the “< !–nextpage–>” tag, i’m trying to code 
   it inside:
 * For example:
    `$content = $post->post_content."< !--nextpage--> Extra info < !--
   nextpage--> Gallery of the post";`
 * So my intention is that the posts look like this:
    Content domain.com/cat/post-
   name Extra info domain.com/cat/post-name/2 Gallery domain.com/cat/post-name/3
 * I’ve found the function that divides the pages, after modifying it I found no
   results, the pagination is displayed but when you try to access domain.com/cat/
   post-name/2 it directly redirects you to domain.com/cat/post-name/ as if not 
   second page was found.
 *     ```
       function setup_postdata( $post ) {
       	global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
   
       	$id = (int) $post->ID;
   
       	$authordata = get_userdata($post->post_author);
   
       	$currentday = mysql2date('d.m.y', $post->post_date, false);
       	$currentmonth = mysql2date('m', $post->post_date, false);
       	$numpages = 1;
       	$multipage = 0;
       	$page = get_query_var('page');
       	if ( ! $page )
       		$page = 1;
       	if ( is_single() || is_page() || is_feed() )
       		$more = 1;
       	//MY MODIFICATION
       	$content = $post->post_content."<!--nextpage--> Page 2";
       	//END OF MYMOD
       	if ( false !== strpos( $content, '<!--nextpage-->' ) ) {
       		if ( $page > 1 )
       			$more = 1;
       		$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
       		$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
       		$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
       		// Ignore nextpage at the beginning of the content.
       		if ( 0 === strpos( $content, '<!--nextpage-->' ) )
       			$content = substr( $content, 15 );
       		$pages = explode('<!--nextpage-->', $content);
       		$numpages = count($pages);
       		if ( $numpages > 1 )
       			$multipage = 1;
       	} else {
       		$pages = array( $post->post_content );
       	}
   
       	do_action_ref_array('the_post', array(&$post));
   
       	return true;
       }
       ```
   
 * I need help!

The topic ‘Multipaging posts from template’ is closed to new replies.

## Tags

 * [multipage](https://wordpress.org/support/topic-tag/multipage/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * 0 replies
 * 1 participant
 * Last reply from: [nosabesnadacom](https://wordpress.org/support/users/nosabesnadacom/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/multipaging-posts-from-template-1/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
