Wordpress Custom Category Template WIth Custom Pagination
1) Create new file for custom taxonomy and upload in wordpress theme taxonomy-(taxonomy-name).php
Example : Id Taxonomy name is "vacancies_uts". Then file name is "taxonomy-vacancies_uts.php".
2) Add this code in functions.php file for pagination anywhere in website
<?php
/************ Pagination Function START *************/
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>';
echo '<li><span>'. $paged . ' of ' . $wp_query->max_num_pages .'</span></li>';
foreach ( $page_format as $page ) {
echo "<li>$page</li>";
}
echo '</ul></div>';
}
}
/************ Pagination Function END *************/
?>
3) Add below code in "taxonomy-vacancies_uts.php" and upload in activated theme.
<?php
/**
* The template for displaying all pages.
*
*/
get_header(); ?>
<?php
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$term_name = $queried_object->name;
?>
<div id="content" class="content" role="main">
<?php
$today = date('m/d/Y');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
//'posts_per_page' => 2,
'post_type' => 'vacancies', //Post Type
'post_status' => 'publish', //Post Status
'tax_query' => array(
array(
'taxonomy' => 'vacancies_uts', //Texonomy Name
'field' => 'id',
'terms' => $term_id
)
),
'meta_query' => array(
array(
'key' => 'last_date', //Meta Field name for compare
'value' => $today, //Meta Field Value compare with this value
'compare' => '>='
)
),
'paged' => $paged
)
);
?>
<?php if ( have_posts() ) : ?>
<div class="cat_heading"><div class="cat_name"><?php echo $term_name;?></div></div>
<table class="vacancies_tables">
<?php while ( have_posts() ) : the_post(); ?>
<?php $vacancies_elgible = get_the_terms( get_the_ID(), 'vacancies_elgible' );?>
<tr>
<td class="vac_title" data-label="Exam"><a href="<?php echo get_the_permalink();?>"><?php echo get_the_title();?></a></td>
<td class="detail_link" data-label="Details"><a class="home_viewmore" href="<?php echo get_the_permalink();?>">View More</a></td>
</tr>
<?php endwhile; ?>
</table>
<div class="custom_pagination"><?php wp_pagination(); ?></div>
<?php else : ?>
<?php //get_template_part( 'no-results', 'page' ); ?>
<?php echo "Sorry, no vacancies available under this Category."; ?>
<?php endif;?>
</div><!-- #content -->
<?php get_footer(); ?>
No comments:
Post a Comment