How can I customize category pages in WordPress?

I’m creating a blog with wordpress, I’m using the DIVI theme and I need to change the appearance of the category pages of the blog…

what’s the easiest way to do that?

Read More

I understood I should look for category.php in the editor and create a new php file, but I couldn’t find anything…

Related posts

2 comments

  1. You will find category.php in your theme folder and customize according to your requirement.

    If category.php file is not exist in your theme then you can create a new file with category.php name and do customization it will automatically uses this file when you will display category posts.

    You need to create category template like below :

    <?php
            /**
        * A Simple Category Template
        */
    
        get_header(); ?> 
    
        <section id="primary" class="site-content">
        <div id="content" role="main">
        <?php 
        // Check if there are any posts to display
        if ( have_posts() ) : ?>
    
        <header class="archive-header">
        <?php
        // Since this template will only be used for Design category
        // we can add category title and description manually.
        // or even add images or change the layout
        ?>
    
        <h1 class="archive-title">Design Articles</h1>
        <div class="archive-meta">
        Articles and tutorials about design and the web.
        </div>
        </header>
    
        <?php
    
        // The Loop
        while ( have_posts() ) : the_post();
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
    
        <div class="entry">
        <?php the_excerpt(); ?>
    
         <p class="postmetadata"><?php
          comments_popup_link( 'No comments yet', '1 comment', '% comments', 'comments-link', 'Comments closed');
        ?></p>
        </div>
    
        <?php endwhile; // End Loop
    
        else: ?>
        <p>Sorry, no posts matched your criteria.</p>
        <?php endif; ?>
        </div>
        </section>
    
        <?php get_sidebar(); ?>
        <?php get_footer(); ?>
    
  2. First off, if there actually exists a file named category.php in your theme folder, it would be unwise to follow @Lalji Nakum’s advice regarding editing the file directly. That would mean that you potentially lose all your changes in a future theme update. Instead you should either create a template file containing the ID or the slug of the category you would like to change. If you are to change the way all categories are displayed, you should instead create a child theme – holding your own version of category.php.

    If there is no category.php in your theme folder, that means the theme controls this view in either archive.php or index.php. There’s a strict hierarchy that WordPress follows, looking for a way to display categories. You would then create the file and make whatever changes to how they are to be displayed. A problem here might be that you would have to make it from scratch. An alternative would be to fall back to the child theme solution, track down where in fact your theme is controlling the view (in any of the two previously mentioned files), duplicate the file into your new child theme and do your changes here.

    It’s now established that you have no category.php in your theme today. You then have to choices, primarily. This is the best one:

    1. Create category.php within your theme folder.
    2. Create the contents of the file from scratch. A good place to start would here:

          <div id="container">
              <div id="content" role="main">
      
                  <h1 class="page-title"><?php
                      printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
                  ?></h1>
                  <?php
                      $category_description = category_description();
                      if ( ! empty( $category_description ) )
                          echo '<div class="archive-meta">' . $category_description . '</div>';
                  get_template_part( 'loop', 'category' );
                  ?>
      
              </div><!-- #content -->
          </div><!-- #container -->
      
    3. Make all your wanted changes to the template.

    4. Finished!

    Creating a child theme is fairly simple, and is explained here: https://codex.wordpress.org/Child_Themes

    Also it sounds like you are looking to create the file from the editor. That’s not built in functionality, but could be managed resorting to creative solutions like this: http://ronangelo.com/create-new-theme-file-in-wp-admin-without-ftp/ . The better alternative would be to use ftp/ssh, though.

    Read more about how category templates, including the mentioned hierarchy, work here: https://codex.wordpress.org/Category_Templates

Comments are closed.