Now i tried to go pdf-market.ir/?paged=2 but it's show 404 Error ! check site, site search
i 1day tried to solve this problem but don't succed. my codes for loop in index.php
<ul class="page_result">
<?php
//$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
'post_type' => 'product',
'stock' => 1,
'posts_per_page' => 16,
'orderby' => 'date',
'order' => 'DESC',
'paged' => 1,
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<div class="bookbox">
<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<div class="bookbox-img">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" style="margin-left: -20px" width="200px" height="200px" />'; ?>
</div>
</a>
<div class="bookbox-bookname"><a data-tooltip="<?php the_title(); ?>" class="bookname tooltip" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<?php $mid_var = get_post_meta($post->ID, 'پدیداورنده',true);
if(isset($mid_var) && !empty($mid_var)) : ?>
<div class="bookbox-dtibook"><span class="garyYekan10">پدیدآورنده:</span>
<?php echo get_post_meta($post->ID, 'پدیداورنده',true); ?>
</div><?php endif; ?>
<?php $mid_var = get_post_meta($post->ID, 'ناشر',true);
if(isset($mid_var) && !empty($mid_var)) : ?>
<div class="bookbox-dtibook"><span class="garyYekan10">ناشر: </span>
<?php echo get_post_meta($post->ID, 'ناشر',true); ?>
</div>
<?php endif; ?>
<?php $mid_var = get_post_meta($post->ID, 'نوبت چاپ',true);
if(isset($mid_var) && !empty($mid_var)) : ?>
<div class="bookbox-dtibook"><span class="garyYekan10">نوبت چاپ:</span>
<?php echo get_post_meta($post->ID, 'نوبت چاپ',true); ?>
</div>
<?php endif; ?>
<div class="bookbox-price"><span class="garytahoma8">قیمت: </span> <?php woocommerce_template_loop_price() ?> </div>
<?php $mid_var = get_post_meta($post->ID, 'موجودی',true);
if(isset($mid_var) && !empty($mid_var)) : ?>
<div class="bookbox-price"><span class="garytahoma8">موجودی: </span><span class="fontgreen10">
<?php echo get_post_meta($post->ID, 'موجودی',true); ?>
</span> </div><?php endif; ?>
<a alt="مشخصات کتاب" href="<?php the_permalink(); ?>"><div title="مشخصات کتاب" alt="مشخصات کتاب" class="bookbox-bookinfo"></div></a>
<a alt="خرید کتاب" href="<?php the_permalink(); ?>&add-to-cart=<?php the_id(); ?>">
<div alt="خرید کتاب" class="bookbox-addcart"></div>
</a>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
<div class="pagination">
<?php
wp_pagination(); ?>
</div>
and my code in function.php > pagination
<?php
function wp_pagination() {
global $wp_query;
$big = 12345678;
$page_format = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'array'
) );
if( is_array($page_format) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
echo '<div><ul>';
foreach ( $page_format as $page ) {
echo "<li>$page</li>";
}
echo '</ul></div>';
}
}
?>
this is all... in searches and archives is show pagination but in home page and example:site.com dont show pagination and it's place just free and no code...
Try this code this will work for you
<?php
global $query_string;
query_posts($query_string . "post_type=product&post_status=publish&posts_per_page=16");
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile;
endif; ?>
<?php pagination_numeric_posts_nav(); ?>
<?php wp_reset_query(); ?>
Put this code in your functions.php file.
function pagination_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->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=""><ul class="pagination">' . "\n";
/** Previous Post Link */
if ( get_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><a href="%s">%s</a></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><a href="%s">%s</a></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><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n";
}
css for pagination.
.navigation li a,
.navigation li a:hover,
.navigation li.active a,
.navigation li.disabled {
color: #fff;
text-decoration:none;
}
.navigation li {
display: inline;
}
.navigation li a,
.navigation li a:hover,
.navigation li.active a,
.navigation li.disabled {
background-color: #6FB7E9;
border-radius: 3px;
cursor: pointer;
padding: 12px;
padding: 0.75rem;
}
.navigation li a:hover,
.navigation li.active a {
background-color: #3C8DC5;
}
I hope this will work for you