Last active
June 6, 2021 16:34
-
-
Save Jany-M/e7ce0c74f76bbb531e57 to your computer and use it in GitHub Desktop.
[WordPress] Post Internal custom Pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Custom Post Pagination | |
function custom_wp_link_pages( $args = '' ) { | |
global $post; | |
// Get Post Type name | |
$post_type_name = ucfirst(get_post_type(get_the_ID())); | |
$defaults = array( | |
'before' => '<li><span class="pagination pagination_title">'.$post_type_name.' Sections:', | |
'after' => '</span></li>', | |
'text_before' => '', | |
'text_after' => '', | |
'next_or_number' => 'number', | |
'nextpagelink' => 'Next page', | |
'previouspagelink' => 'Previous page', | |
'pagelink' => '%', | |
'echo' => 1 | |
); | |
$r = wp_parse_args( $args, $defaults ); | |
$r = apply_filters( 'wp_link_pages_args', $r ); | |
extract( $r, EXTR_SKIP ); | |
global $page, $numpages, $multipage, $more, $pagenow; | |
$output = ''; | |
if ( $multipage ) { | |
if ( 'number' == $next_or_number ) { | |
$output .= $before; | |
for ( $i = 1; $i < ( $numpages + 1 ); $i = $i + 1 ) { | |
$j = str_replace( '%', $i, $pagelink ); | |
$output .= ' '; | |
if ( $i != $page || ( ( ! $more ) && ( $page == 1 ) ) ) : | |
// Add class to the link | |
$add_class = str_replace('<a', '<a class="pagination" ', _wp_link_page( $i )); | |
$output .= '<li>'.$add_class; | |
else : | |
$output .= '<li><span class="pagination current" title="This Page">'; | |
endif; | |
$output .= $text_before . $j . $text_after; | |
if ( $i != $page || ( ( ! $more ) && ( $page == 1 ) ) ) | |
$output .= '</a></li>'; | |
else | |
$output .= '</span></li>'; | |
} | |
$output .= $after; | |
} else { | |
if ( $more ) { | |
$output .= $before; | |
$i = $page - 1; | |
if ( $i && $more ) { | |
$output .= '<li>'. _wp_link_page( $i ); | |
$output .= $text_before . $previouspagelink . $text_after . '</a></li>'; | |
} | |
$i = $page + 1; | |
if ( $i <= $numpages && $more ) { | |
$output .= '<li>'._wp_link_page( $i ); | |
$output .= $text_before . $nextpagelink . $text_after . '</a></li>'; | |
} | |
$output .= $after; | |
} | |
} | |
} | |
if ( $echo ) | |
echo $output; | |
return $output; | |
} | |
// Add Post Pagination Button -> Next Page in TinyMCE Editor | |
// https://shellcreeper.com/?p=889 | |
function add_next_page_button( $buttons, $id ){ | |
/* only add this for content editor */ | |
if ( 'content' != $id ) | |
return $buttons; | |
/* add next page after more tag button */ | |
array_splice( $buttons, 13, 0, 'wp_page' ); | |
return $buttons; | |
} | |
add_filter( 'mce_buttons', 'add_next_page_button', 1, 2 ); // 1st row | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment