So i change my wordpress permalink with custom structure "/%category%/%postname%/".
However, if i type manually "/poem/page/2", then it works. But the content of every page is the same. Wether it was "/page/3" or "/page/4", it was all the same.
at first, when i access "/page/2/", my page was giving "404 error". But i got this code from the internet, and when i use the code, it started to work. But, the content of every page is the same. The code goes on like this :
on function.php:
function vipx_filter_category_rewrite_rules( $rules ) {
$categories = get_categories( array( 'hide_empty' => false ) );
if ( is_array( $categories ) && ! empty( $categories ) ) {
$slugs = array();
foreach ( $categories as $category ) {
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
if ( 0 == $category->category_parent ) {
$slugs[] = $category->slug;
} else {
$slugs[] = trim( get_category_parents( $category->term_id, false, '/', true ), '/' );
}
}
}
if ( ! empty( $slugs ) ) {
$rules = array();
foreach ( $slugs as $slug ) {
$rules[ '(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')(/page/(\d)+/?)?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
}
}
}
return $rules;
}```
this is my loop post :
?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
echo $paged;
$term = get_queried_object();
$data = array( 'posts_per_page' => 2, 'category_name' => $term->slug, 'page'=>$paged );
$get_category_post = new WP_Query( $data );
?>
<?php if ( $get_category_post->have_posts() ) : while ( $get_category_post->have_posts() ) : $get_category_post->the_post(); ?>
<div class="post__list">
<?php if($term->slug === 'analect' || $term->slug === 'collection') { ?>
<span>for other categories</span>
<?php } else {?>
<span> <?php the_content(); ?> </span>
<?php } ?>
</div>
<?php endwhile; ?>
<?php
next_posts_link();
previous_posts_link();
?>
<?php endif; ?>
Related
I have the following code inside the search results page and I want it not to show it when there is no content in any part.
if ( have_posts() ) {
$types = array('singer', 'music', 'album');
foreach( $types as $type ){
if( $type == 'singer'){
echo ' <h1>Singers</h1> ';
} elseif ( $type == 'music'){
echo '<h1>Musics</h1>';
}
elseif ( $type == 'album'){
echo '<h1>Albums</h1>';
}
while( have_posts() ){
the_post();
if( $type == get_post_type() ){
the_post_thumbnail('medium'); ?>
<h3><a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?>
</a></h3>
<?php
}
}
rewind_posts();
}
} else {
echo us_translate( 'No results found.' );
}
This is not a good solution, but should work)
$types = array(
'singer' => array( 'title' => 'Singers', 'content' => '' ),
'music' => array( 'title' => 'Musics', 'content' => '' ),
'album' => array( 'title' => 'Albums', 'content' => '' ),
);
if ( have_posts() ) {
while( have_posts() ) {
the_post();
$type = get_post_type();
if ( array_key_exists( $type, $types ) ) {
$types[ $type ][ 'content' ] .= get_the_post_thumbnail( null, 'medium' );
$types[ $type ][ 'content' ] .= '<h3><a href="' . get_the_permalink() . '">' . get_the_title() . '</h3>';
}
}
foreach( $types as $k => $v ) {
if ( $v[ 'content' ] ) {
echo '<h1>' . $v[ 'title' ]. '</h1>' . $v[ 'content' ];
}
}
} else {
echo us_translate( 'No results found.' );
}
I want to display the first 4 product attributes on each product card.
That code shows me only specific attributes. Any way to get these attributes? Every category has own attributes so I cant do it for every category on the site. Please help me
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$has_row = false;
$attributes = $product->get_attributes();
ob_start();
?>
<div class="product_attributes">
<?php foreach ( $attributes as $attribute ) :
if ( empty( $attribute['is_visible'] ) || ( $attribute['is_taxonomy'] && ! taxonomy_exists( $attribute['name'] ) ) )
continue;
$values = wc_get_product_terms( $product->get_id(), $attribute['name'], array( 'fields' => 'names' ) );
$att_val = apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
if( empty( $att_val ) )
continue;
$has_row = true;
?>
<div class="col">
<div class="att_label"><?php echo wc_attribute_label( $attribute['name'] ); ?></div>
<div class="att_value"><?php echo $att_val; ?></div><!-- .att_value -->
</div><!-- .col -->
<?php endforeach; ?>
</div><!-- .product_attributes -->
<?php
if ( $has_row ) {
echo ob_get_clean();
} else {
ob_end_clean();
}
So I wrote other function:
if( $_product->has_attributes() ){
// Initializing
$attributes = array();
// Loop through product attributes
$i = 0;
foreach( $_product->get_attributes() as $taxonomy => $attribute ){
// The product attribute label name
$attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;
// Set each product attribute with its values in an array
// $attributes[] = '<strong>'.$attribute_name.'</strong>: '.$_product->get_attribute($taxonomy);
?>
<div class="prodAttr">
<p class="prodAttr__title"><?php echo $attribute_name?></p>
<p class="prodAttr__value"><?php echo $_product->get_attribute($taxonomy) ?></p>
</div>
<?php
$i++;
if ($i == 4) break;
}
// Display (output)
// echo '<div class="product-attributes"><span>'. implode( '</span> <span>', $attributes ) . '</span></div>';
}
It works. Closed
I have code to show get_meta_post per page this my code
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$metas = get_post_meta(get_the_ID(),'value_gallery',false);
//var_dump($metas); ==> will output array(1) { [0]=> string(29) "1434,1402,1434,1435,1398,1434" }
foreach ($metas as $key ) {
$key_val = explode(",", $key);
$page = get_query_var('page');
$page = $page > 1 ? $page - 1 : 0 ;
if (isset($key_val[$page])) {
echo "<div class='col-lg-4'>".
wp_get_attachment_image($key_val[$page],"cherry-thumb-a") ."</div>";
}
}
endwhile;
else :
_e('Sorry, no posts matched your criteria.');
endif;
so this code will show my image using
wp_get_attachment_image($key_val[$page],"cherry-thumb-a")
and will paginate with link
https://yourpage.com/post-name/2
but this code just show image 1 per page , my problem is how to show 4 image per page , and how to change link paginate to
https://yourpage.com/post-name/page/2
i will hapyy if anyone can help me
Update
thankyou for attention , i was try adding array_chunk , and adding pagination , but it still not work , my full code:
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array('posts_per_page' => 1, 'paged' => $paged );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$metas = get_post_meta(get_the_ID(),'value_gallery',false);
foreach ($metas as $meta) {
$key_val = explode(",", $meta);
$image_chunk = array_chunk($key_val, 4);
$page = get_query_var('page');
$page = $page > 1 ? $page - 1 : 0 ;
if (isset($key_val[$page])) {
foreach ($image_chunk[$page] as $image) {
echo "<div class='col-lg-4'>".
wp_get_attachment_image($image,"cherry-thumb-a") ."</div>";
}
}
}
endwhile;
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
endif;
many thank for attention
use array_chunk()
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$metas = get_post_meta(get_the_ID(),'value_gallery',false);
foreach ($metas as $meta) {
$key_val = explode(",", $meta);
$image_chunk = array_chunk($key_val, 4);
$page = get_query_var('page');
$page = $page > 1 ? $page - 1 : 0 ;
if (isset($key_val[$page])) {
foreach ($image_chunk[$page] as $image) {
echo "<div class='col-lg-4'>".
wp_get_attachment_image($image,"cherry-thumb-a") ."</div>";
}
}
}
endwhile;
endif;
Adding pagination for single post pages
Place this function in your functions.php
add_action('redirect_canonical', 'single_pagination_fix');
public static function single_pagination_fix( $redirect_url ) {
if ( is_paged() && is_singular() ) {
$redirect_url = false;
}
return $redirect_url;
}
I have a question: In wordpress, how can I display posts in a category on a page ?. I have many categories, and in a page, I just only want posts in a category are displayed.
Thanks for your support !
Here is an alternative to a plugin. This is a dynamic page template. This template lets you choose which category's posts to display on the specific page. You can use this template over and over inside the same theme
Add this to your functions.php or any functions related file
<?php
/**-----------------------------------------------------------------------------
*
*Add a post metabox with options to the admin page screen.
*After selcting the page-pop.php template as a page template,
*this metabox will appear in the admin page screen.
*From here you can choose which category's posts to display
*and how the posts will be displayed on the page
*
* #package WordPress
* #subpackage Twenty_Fourteen
* #since Twenty Fourteen 1.0
*
*------------------------------------------------------------------------------*/
/**-----------------------------------------------------------------------------
*
*1. Only add meta boxes for the pop template
*
* #since Twenty Fourteen 1.0
*
*------------------------------------------------------------------------------*/
add_action('admin_init', 'pietergoosen_add_pop_meta_box');
function pietergoosen_add_pop_meta_box(){
$post_id = isset( $_GET['post'] ) ? $_GET['post'] : 0 ;
if($post_id) {
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
if ($template_file == 'page-pop.php') {
add_meta_box('pop_meta_box', __( 'Page of Posts with the same name', 'pietergoosen' ), 'pietergoosen_pop_meta_options', 'page', 'side', 'core');
} else {
$meta = get_post_meta($post_id, '_cat_id', true);
if( $meta ) {
pietergoosen_pop_update_post_meta($post_id, '_cat_id', '');
pietergoosen_pop_update_post_meta($post_id, '_page_title', '');
pietergoosen_pop_update_post_meta($post_id, '_posts_title', '');
pietergoosen_pop_update_post_meta($post_id, '_order_by', '');
pietergoosen_pop_update_post_meta($post_id, '_asc', '');
pietergoosen_pop_update_post_meta($post_id, '_post_count', '');
pietergoosen_pop_update_post_meta($post_id, '_days', '');
remove_meta_box( 'pop_meta_box', 'page', 'side' );
}
}
}
add_action('save_post', 'pietergoosen_pop_update_post_meta_box');
}
/**-----------------------------------------------------------------------------
*
*2. Built the list to display the options in the metabox
*
* #since Twenty Fourteen 1.0
*
*------------------------------------------------------------------------------*/
$order_list = array(
'none' => array( 'value' => 'none','label' => 'None' ),
'id' => array( 'value' => 'ID','label' => 'Post ID' ),
'author' => array( 'value' => 'author','label' => 'Author' ),
'title' => array( 'value' => 'title','label' => 'Post Title' ),
'date' => array( 'value' => 'date', 'label' => 'Post Date'),
'modified' => array( 'value' => 'modified','label' => 'Modified Date' ),
'parent' => array( 'value' => 'parent','label' => 'Parent Post' ),
'rand' => array( 'value' => 'rand','label' => 'Random' ),
'comment_count' => array( 'value' => 'comment_count','label' => 'Comment Count' ),
'menu_order' => array( 'value' => 'menu_order','label' => 'Menu Order' ),
);
$sort = array(
'DESC' => array( 'value' => 'DESC','label' => 'Descending' ),
'ASC' => array( 'value' => 'ASC','label' => 'Ascending' ),
);
function pietergoosen_pop_meta_options(){
$post_id = !empty($_GET['post']) ? $_GET['post'] : 0;
if( !$post_id ) return;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
if ($template_file != 'page-pop.php') return;
global $order_list,$post_styles,$sort;
$categories = get_categories();
//Check if we have values
$post_meta=array();
$post_meta = get_post_meta( $post_id,false );
$cat_id = isset( $post_meta['_cat_id'] ) ? $post_meta['_cat_id'][0] : 1;
$page_title = isset( $post_meta['_page_title'] ) && $post_meta['_page_title'] ? $post_meta['_page_title'][0] : '';
$posts_title = isset( $post_meta['_posts_title'] ) && $post_meta['_posts_title'] ? $post_meta['_posts_title'][0] : '';
$order_by = isset( $post_meta['_order_by'] ) ? $post_meta['_order_by'][0] : 'date';
$asc = isset( $post_meta['_asc'] ) ? $post_meta['_asc'][0] : 'DESC';
$post_count = isset( $post_meta['_post_count'] ) ? $post_meta['_post_count'][0] : get_option('posts_per_page');
if(!$post_count || !is_numeric( $post_count )) $post_count = get_option('posts_per_page');
$days = isset( $post_meta['_days'] ) ? $post_meta['_days'][0] : '0';
if($days && !is_numeric( $days )) $days = '0';
?>
<!-- Sart the meta boxes -->
<div class="inside">
<p><label><strong><?php _e( 'Page Title', 'pietergoosen' ); ?></strong></label></p>
<input id="_posts_title" name="_posts_title" type="text" style="width: 98%;" value="<?php echo $posts_title; ?>"/>
<p><label><strong><?php _e( 'Post Title', 'pietergoosen' ); ?></strong></label></p>
<input id="_page_title" name="_page_title" type="text" style="width: 98%;" value="<?php echo $page_title; ?>"/>
<p><label><strong><?php _e( 'Category', 'pietergoosen' ); ?></strong></label></p>
<select id="_cat_id" name="_cat_id">
<?php
//Category List
foreach ($categories as $cat) :
$selected = ( $cat->cat_ID == $cat_id ) ? ' selected = "selected" ' : '';
$option = '<option '.$selected .'value="' . $cat->cat_ID;
$option = $option .'">';
$option = $option .$cat->cat_name;
$option = $option .'</option>';
echo $option;
endforeach;
?>
</select>
<p><label><strong><?php _e( 'Sort by', 'pietergoosen' )?></strong></label></p>
<select id="_order_by" name="_order_by">
<?php
foreach ($order_list as $output) :
$selected = ( $output['value'] == $order_by ) ? ' selected = "selected" ' : '';
$option = '<option '.$selected .'value="' . $output['value'];
$option = $option .'">';
$option = $option .$output['label'];
$option = $option .'</option>';
echo $option;
endforeach;
?>
</select>
<p><label><strong><?php _e( 'Order', 'pietergoosen' )?><strong></label></p>
<select id="_asc" name="_asc">
<?php
foreach ($sort as $output) :
$selected = ( $output['value'] == $asc ) ? ' selected = "selected" ' : '';
$option = '<option '.$selected .'value="' . $output['value'];
$option = $option .'">';
$option = $option .$output['label'];
$option = $option .'</option>';
echo $option;
endforeach;
?>
</select>
<p><strong><label><?php _e( 'Posts per Page', 'pageofposts' ); ?><strong></label></p>
<input id="_post_count" name="_post_count" type="text" value="<?php echo $post_count; ?>" size="3" />
<p><strong><label><?php _e( 'Posts in the last days', 'pageofposts' ); ?><strong></label></p>
<input id="_days" name="_days" type="text" value="<?php echo $days; ?>" size="3" />
</div>
<!-- End page of posts meta box -->
<?php
}
function pietergoosen_pop_update_post_meta_box( $post_id ){
if ( empty( $_POST ) ) {
return;
} else {
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
if ($template_file != 'page-pop.php') return;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
} else {
if ( $_POST['post_type'] == 'page' ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
$meta = isset( $_POST['_cat_id'] ) ? $_POST['_cat_id'] : 1;
pietergoosen_pop_update_post_meta($post_id, '_cat_id', $meta);
$meta = isset( $_POST['_page_title'] ) ? $_POST['_page_title'] : '';
pietergoosen_pop_update_post_meta($post_id, '_page_title', $meta);
$meta = isset( $_POST['_posts_title'] ) ? $_POST['_posts_title'] : '';
pietergoosen_pop_update_post_meta($post_id, '_posts_title', $meta);
$meta = isset( $_POST['_order_by'] ) ? $_POST['_order_by'] : 'date';
pietergoosen_pop_update_post_meta($post_id, '_order_by', $meta);
$meta = isset( $_POST['_asc'] ) ? $_POST['_asc'] : 'DESC';
pietergoosen_pop_update_post_meta($post_id, '_asc', $meta);
$meta = isset( $_POST['_post_count'] ) ? $_POST['_post_count'] : get_option('posts_per_page');
pietergoosen_pop_update_post_meta($post_id, '_post_count', $meta);
$meta = isset( $_POST['_days'] ) ? $_POST['_days'] : 0;
pietergoosen_pop_update_post_meta($post_id, '_days', $meta);
return;
}
}
}
function pietergoosen_pop_update_post_meta($post_id, $key, $data) {
$post_meta = get_post_meta($post_id, $key, true);
if( $data != '' && $post_meta != $data) {
update_post_meta($post_id, $key, $data);
} elseif ( $post_meta != '' && $data == '' ) {
delete_post_meta($post_id, $key);
}
}
?>
Secondly, the page template. You have to call this template page-pop.php
<?php
/**
* Template Name: Page of Posts
*/
get_header(); ?>
<?php
//See if we have any values
$post_meta=array();
$post_meta = get_post_meta( $post->ID,false );
$catid = isset( $post_meta['_cat_id'] ) ? $post_meta['_cat_id'][0] : 1;
$page_title = isset( $post_meta['_page_title'] ) ? $post_meta['_page_title'][0] : '';
$posts_title = isset( $post_meta['_posts_title'] ) ? $post_meta['_posts_title'][0] : '';
$orderby = isset( $post_meta['_order_by'] ) ? $post_meta['_order_by'][0] : 'date';
$asc = isset( $post_meta['_asc'] ) ? $post_meta['_asc'][0] : 'DESC';
$list_style = isset( $post_meta['_list_style'] ) ? $post_meta['_list_style'][0] : 'default';
$post_count = isset( $post_meta['_post_count'] ) ? $post_meta['_post_count'][0] : get_option('posts_per_page');
if(!$post_count || !is_numeric( $post_count )) $post_count = get_option('posts_per_page');
$days = isset( $post_meta['_days'] ) ? $post_meta['_days'][0] : 0;
if($days && !is_numeric( $days )) $days = 0;
$do_not_show_stickies = ($list_style == 'default') ? 0 : 1;
?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<!-- Page Title -->
<?php if( $posts_title ) : ?>
<article id="posts-title">
<header class="entry-header">
<h2 class="entry-title"><?php echo $posts_title; ?></h2>
</header><!-- .entry-header -->
</article><!-- #posts-title -->
<?php endif; ?>
<?php the_post(); ?>
<?php global $post;
if( $post->post_content || $page_title ) : ?>
<div class="entry-content">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if( $page_title ) : ?>
<header class="entry-header">
<h1 class="entry-title"><?php echo $page_title; ?></h1>
</header><!-- .entry-header -->
<?php endif; ?>
<?php if( $post->post_content ) : ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'pietergoosen' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
</footer><!-- .entry-meta -->
<?php endif; ?>
</article><!-- #post-<?php the_ID(); ?> -->
</div>
<?php endif; ?>
<?php
/* Do we have any category */
global $post;
// Save posts for later use
$tmp_post = $post;
$args = array(
'cat' => $catid,
'posts_per_page' => $post_count,
'paged' => $paged,
'orderby' => $orderby,
'order' => $asc,
'ignore_sticky_posts' => $do_not_show_stickies,
);
if( $days ) {
function pop_filter_where( $where = '') {
global $days;
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-' .$days .' days')) . "'";
return $where;
}
add_filter( 'posts_where', 'pop_filter_where' );
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query( $args );
remove_filter( 'posts_where', 'pop_filter_where' );
} else {
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query( $args );
}
// Output
if ( $wp_query->have_posts() ) :
// Start the Loop.
while ( $wp_query->have_posts() ) : $wp_query->the_post();
get_template_part( 'content', get_post_format() );
endwhile;
pietergoosen_pagination();
else :
get_template_part( 'content', 'none' );
endif; ?>
<?php
// Reset the post to the page post
$post = $tmp_post;
?>
<?php if ( comments_open() || get_comments_number() ) {
comments_template();
} ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar( 'content' ); ?>
</div><!-- #main-content -->
<?php
get_footer();
You can now simply create a new page and choose the "page of posts" template, and publish your page. Once that is done, the Page of Posts metabox will appear. From that you can choose the category to display on that page.
There's a plugin that will do that. http://wordpress.org/plugins/posts-per-cat/
He used the plugin then set it to a ridiculous number so that it would show all the categories on the page. Here's the link to the website I found the answer on:
https://wordpress.stackexchange.com/questions/45856/show-posts-of-category-in-a-page
I hope that helps.
I have 6 posts in Wordpress. I'm trying to display last 5 posts on page. Here is my code:
<?php
/*
Template Name: Posts Template
*/
?>
//header...
<?php $the_query = new WP_Query( array('showposts' => 5, 'post_type' => 'post')); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<h1><?php echo the_title(); ?></h1>
<?php endwhile; ?>
<?php posts_nav_link(); ?>
//footer
Pagination shows me that there is 4 pages, but like I said I have only 6 posts, so how it is possible? Also Pagination seems to not work correctly, doesn't matter on what page I am, it shows always last 5 posts.
Any idea what am I doing wrong?
Try adding a paged parameter to your query. You can also have a read of the documentation on the topic, there are some examples. Oh, and it's probably more forward-looking to use posts_per_page instead of showposts.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_Query( array(
'posts_per_page' => 5,
'post_type' => 'post',
'paged' => $paged
));
Add this code to functions.php
function posts_nav_link( $query_object, $show_previous_posts_link = false, $show_next_posts_link = false ) {
if( is_singular() )
return;
/** Stop execution if there's only 1 page */
if( $query_object->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $query_object->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="navigation"><ul>' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() && $show_previous_posts_link)
printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() && $show_next_posts_link )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n";
}
And use posts_nav_link($the_query):
<?php
/*
Template Name: Posts Template
*/
?>
//header...
<?php $the_query = new WP_Query( array('showposts' => 5, 'post_type' => 'post')); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<h1><?php echo the_title(); ?></h1>
<?php endwhile; ?>
<?php posts_nav_link($the_query); ?>
//footer