Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

add the tag nextpage in the file.php WordPress

  • SOLVED

i need to add this tag <!--nextpage--> in the file page.php

I try this :




<?php
$MyContent = "first part of the content\n";
$MyContent .= "<!--nextpage-->\n";
$MyContent .= "second part of the content";

$MyContent = apply_filters('the_content', $MyContent );
echo $MyContent;
?>


that doesn't work

an idea ?

Answers (4)

2011-07-25

Daniele Raimondi answers:

You don't have to open the page.php template file with an HTML editor; you have to insert that code in the tinyMCE editor area, in page edit section, when you want to create a "multipage page"(!).
Create your new page, switch to HTML mode, paste that code, then switch back to visual mode.
You Should have a button also in visual mode to get the same result.

If you have added the needed code as described in the rest of linked tutorial, your new page will have its subpages treated as real wordpress pages


jevusi comments:

i know, thanks...
but i want add this tag in the file page.php


Daniele Raimondi comments:

Please, be more specific on what is your goal. Why do you wann add that tag on the template page file?


jevusi comments:

I use this code : http://betterwp.net/98-wordpress-create-fake-pages/

I want to display a specific content.
For example, my content could be


$type = get_post_meta($post->ID, 'type', true);
$color = get_post_meta($post->ID, 'color', true);
$size = get_post_meta($post->ID, 'size', true);


the type is <? echo $type ?>
<!--nextpage-->
the color is <? echo $color ?
<!--nextpage-->
the size is <? echo $size ?


jevusi comments:

so, you have an idea please ?


Daniele Raimondi comments:

I'm sorry but I'm still not able to understand why you are trying to paginate infos like this, hard-coding all in the template.
Code explained [[LINK href="http://betterwp.net/98-wordpress-create-fake-pages/"]]here[[/LINK]] just gives you a way to autocreate x subpages of a page, in a way they behave like x real pages.
It doesn't give you a way to split page content from template file.
If you wanna show meta values splitted in subpages from the current one, make it all from the visual editor: install a plugin that prints meta values using shortcodes, and then paginate those infos like you want.





jevusi comments:

ok but that's not a response to my question. So have you a response ? I want to apply this tag <!--nextapage--> in a file. That's all. Do you understand ?


jevusi comments:

In the page editor i have several custom fields.

All this fields values ​​are divided into three pages in the frontoffice.
(One page in the backoffice = three pages in the frontoffice)

So i use this process to create fake pages. But this process works with the_content.

In my case i don't use the_content but values of several custom fields.

Tell me if it's clear or not.

Could you help me ? :-))
Thanks


Daniele Raimondi comments:

OK, now that's more clear.
As I write above, If you wanna show meta values splitted in subpages, the easiest way is to install a plugin that prints meta values using shortcodes. In this way you can insert those values (using short codes) in the content of the page and then paginate them using <!--nextpage-->, all from the visual editor in the backend.

For example,
suppose you have 3 custom fields,

type
color
size

associate to each page you create in the backend.

1) Insert this code in your function.php

add_shortcode('field', 'shortcode_field');
function shortcode_field($atts){
extract(shortcode_atts(array(
'post_id' => NULL,
), $atts));
if(!isset($atts[0])) return;
$field = esc_attr($atts[0]);
global $post;
$post_id = (NULL === $post_id) ? $post->ID : $post_id;
return get_post_meta($post_id, $field, true);
}


2) Edit or create a new page and fill custom fields.
3) In the content of the page (tinyMCE area) insert text like this:

Those are my custom fields value:

<!--nextpage-->
the color is [field "color"]
<!--nextpage-->
the type is [field "type"]
<!--nextpage-->
the size is [field "size"]


The function above just "translate" [field "color"], for example, in the metavalue you have entered for custom field <em>color</em>, and the code your are using for fake pages will do the rest, paginating your content.

Hope this can help.


jevusi comments:

It's a very nice response... but...
my custom fields are created by the plugin "magic fields" and i use the system "duplicate group". With magic fields you can create a group of fields and you can duplicate a group if you need.

With your code i don't think i can display ll the duplicated group.
Can i ?


Daniele Raimondi comments:

In this case, you should modfy the function "<em>shortcode_field</em>" to manage other parameters (for example the group number) and subsitute the last line


return get_post_meta($post_id, $field, true);


with the code that Magic Fields uses to query values from groups and duplicate groups (using new parameters you have passed).
In this way you can still use the same shortcode, foe example:

[field "name" group=x]


to load metavalues using MF methods instead of default WP method <em>get_post_meta()</em>.

But it's quite time-consuming to deal with magic fields methods documentation... Better ask to Gnuget (David V) and Hunk (Edgar G) in they google group!


jevusi comments:

thanks daniele
i think a simple rewrite rule can help me, no ?
so i ask a new question for that : [[LINK href="http://wpquestions.com/question/show/id/2729"]]http://wpquestions.com/question/show/id/2729[[/LINK]]

maybe could you have a response :-)

2011-07-25

Romel Apuya answers:

Well I guess you have not followed the instruction on how to add that code?


jevusi comments:

i have followed the instruction, no problem, thanks
but i want know add this tag in the file page.php
that's my question


jevusi comments:

so, you have an idea please ?

2011-07-25

Hardeep Singh answers:

I am not sure, why you need it but if you need it you need it.

How to apply this, below are the options/ways to achieve:

- As mentioned by Daniele, update the page using page editor. (if this is for a specific page only)
- Open page.php and write the code where ever you want to place
- If you want to use filters, then use add_filter as in example below:
<?php add_filter('the_content', function($content) { return ''. $content. '';}) ?>

You can customize the return part as per your need.

Hope this helps!


Hardeep Singh comments:

I am not sure, why you need it but if you need it you need it.

How to apply this, below are the options/ways to achieve:

- As mentioned by Daniele, update the page using page editor. (if this is for a specific page only)
- Open page.php and write the code where ever you want to place
- If you want to use filters, then use add_filter as in example below:
<?php add_filter('the_title', function($title) { return ''. $title. '';}) ?>
You can customize the return part as per your need.

Hope this helps!


jevusi comments:

In the page editor i have several custom fields.

All this fields values ​​are divided into three pages in the frontoffice.
(One page in the backoffice = three pages in the frontoffice)

So i use this [[LINK href="http://betterwp.net/98-wordpress-create-fake-pages/"]]process[[/LINK]] to create fake pages. But this process works with the_content.

In my case i don't use the_content but values of several custom fields.

Tell me if it's clear or not.

Could you help me ? :-))
Thanks

2011-07-26

Peter Michael answers:


global $post;
$post->post_content = '';
$post->post_content .= 'the type is post';
$post->post_content .= '<!--nextpage-->';
$post->post_content .= 'the color is red';
$post->post_content .= '<!--nextpage-->';
$post->post_content .= 'the size is large';
setup_postdata($post);


jevusi comments:

could you explain please ?


Peter Michael comments:

File loop-page.php from theme TwentyTen:

<?php
/**
* The loop that displays a page.
*
* The loop displays the posts and the post content. See
* http://codex.wordpress.org/The_Loop to understand it and
* http://codex.wordpress.org/Template_Tags to understand
* the tags used in it.
*
* This can be overridden in child themes with loop-page.php.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.2
*/
?>

<?php

if ( have_posts() ) while ( have_posts() ) : the_post();

$global $post;

$post->post_content = '';
$post->post_content .= 'the type is post';
$post->post_content .= '<!--nextpage-->';
$post->post_content .= 'the color is red';
$post->post_content .= '<!--nextpage-->';
$post->post_content .= 'the size is large';

setup_postdata($post);

?>

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_front_page() ) { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>

<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->

<?php comments_template( '', true ); ?>

<?php endwhile; // end of the loop. ?>


jevusi comments:

This code works but there is a small problem.
In [[LINK href="http://wpquestions.com/question/version/id/531"]]the first version[[/LINK]] of my question I said:
"i use this code: [[LINK href="http://betterwp.net/98-wordpress-create-fake-pages/"]]http://betterwp.net/98-wordpress-create-fake-pages/[[/LINK]]"
After I removed this sentence because Daniele and Romel spoke only about this code instead of answering my question...

Your code works but suddenly [[LINK href="http://betterwp.net/98-wordpress-create-fake-pages/"]]this code[[/LINK]] no longer works.

With this code i have a pagination like that :


Plugin Installation
Plugin Usage
Plugin Screenshots
Plugin Changelog
Users' Feedbacks


if i clik on "plugin usage" i go to http://mysite.com/title-of-my-page/2 but the url is rewrite : http://mysite.com/title-of-my-page/usage
With your code all is ok but if i click on "plugin usage" noting is displayed.
I must click on 2 (in the pagination displayed by wp_link_pages ) to display the content of the page 2, but the url is also http://mysite.com/title-of-my-page/2
instead of http://mysite.com/title-of-my-page/usage

have you a solution for this problem please ?


Peter Michael comments:

If you want to use custom permalinks (http://mysite.com/title-of-my-page/usage) you should use the plugin. If you want to have WordPress pagination (1,2,3) you can use my code. Not both. My code replaces all 'post_content' with the hard coded values I have given.

The proper solution would be to create a new page in WP, titled 'Hardcoded Pagination' for ex., then copy the file page.php to page-hardcoded-pagination.php, copy the file loop-page.php to loop-page-hardcoded-pagination.php and replace get_template_part( 'loop', 'page' ); with get_template_part( 'loop', 'page-hardcoded-pagination' ); in the file page-hardcoded-pagination.php

This way, only the page 'Hardcoded Pagination' contains my code, all other pages functionality remain as usual and you can use the plugin there.

HTH


jevusi comments:

<blockquote>If you want to use custom permalinks (http://mysite.com/title-of-my-page/usage) you should use the plugin. If you want to have WordPress pagination (1,2,3) you can use my code. Not both. </blockquote>

arf, in this case, your response is not a good response for me :-/