0

I'm developing custom theme that should show all categories on a single page in /category path.

When i navigate to /category/some-category, i can see all posts that belong to that category, but when i go to /category, i get 404 error.

I have category.php file with following loop:

<?php define( 'WP_USE_THEMES', false ); get_header(); ?>


<div class="archive-meta"><?php echo category_description(); ?></div>


<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

 <div class="row">
    <div class="article">

        <div class="small-12">
            <h4><a href="<?php the_permalink() ?>"> <?php the_title(); ?></a></h4>
        </div>

        <div class="small-12 columns">
            <?php the_post_thumbnail() ?>
        </div>
        <div class="small-12 columns">
            <?php the_excerpt(); ?>
        </div>
    </div>
</div>                         


<?php endwhile; else : ?>
    <?php wp_list_categories(); ?>
<?php endif; ?>

<div class="small-12 columns">
    <?php custom_pagination() ?>
</div>


<?php get_footer(); ?>

How can i show all categories when user navigate to /category/?

1

I believe there is no such "All Categories" archive page natively (because it would be just like the blog page - since every post have a category) . I recommend you to create a page template copying that code and modifying the query to include all posts and then creating a page with the slug 'category'.

<?php
/*
* Template Name: Category
*/
?>

<?php define( 'WP_USE_THEMES', false ); get_header(); ?>


<div class="archive-meta">All categories of our blog!</div>


<?php query_posts('post_type=post'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

 <div class="row">
    <div class="article">

        <div class="small-12">
            <h4><a href="<?php the_permalink() ?>"> <?php the_title(); ?></a></h4>
        </div>

        <div class="small-12 columns">
            <?php the_post_thumbnail() ?>
        </div>
        <div class="small-12 columns">
            <?php the_excerpt(); ?>
        </div>
    </div>
</div>                         


<?php endwhile; else : ?>
    <?php wp_list_categories(); ?>
<?php endif; ?>

<div class="small-12 columns">
    <?php custom_pagination() ?>
</div>


<?php get_footer(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.