The past week I've been trying to figure it out on creating a custom category page with pagination. I've tried in so many ways but I cant get the pagination right. If anyone of you can help.
What I actually wanted to do is in my wordpress theme I wanted to create a custom template that displays all the category that has the same name as the page name.
EXAMPLE
I have created a page called 'php' with template set to the template I was trying to build. And when I click that page I wanted to show all the post that belong to 'php' category.
Here the code sample...
<?php
/**
* Template Name: Category Temeplate
*
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
$category = get_post();
$category = $category->post_title;
$query = new WP_Query( array(
'category_name' => $category,
'order' => 'asc',
'post_type' => 'post',
'post_status' => 'publish',
));
?>
<?php
if ($query->have_posts()) {
while ($query->have_posts()) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>"
<header class="entry-header">
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php
the_content();
?>
</div><!-- .entry-content -->
</article><!-- #post-## --><hr>
<?php endwhile; ?>
<?php the_paging_nav(); ?>
<?php
}
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>