Skip to content

Instantly share code, notes, and snippets.

@geoffreycrofte
Last active July 23, 2021 08:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geoffreycrofte/d3b5c0ab64e97278248df59bc53082f0 to your computer and use it in GitHub Desktop.
Save geoffreycrofte/d3b5c0ab64e97278248df59bc53082f0 to your computer and use it in GitHub Desktop.
Page Template to list all your categories with their title, description and RSS link
<?php
/**
* @package WordPress
* @subpackage Creative Juiz v2
* Template Name: Category List
* @see: https://gist.github.com/geoffreycrofte/d3b5c0ab64e97278248df59bc53082f0
* @author: Geoffrey Crofte
*/
get_header(); ?>
<main class="main-content" id="main-content">
<div class="inside">
<div class="part-main">
<?php
juiz_breadcrumbs();
if (have_posts()) : while (have_posts()) : the_post();
?>
<div class="article block post-<?php the_ID(); ?> pt-page hentry" id="post-<?php the_ID(); ?>">
<h1 class="article-title entry-title"><?php the_title() ?></h1>
<div class="separator"></div>
<div class="entry-content">
<?php
the_content();
endwhile;
endif;
// Get all the categories
$categories = get_categories();
$cat_output = '<dl>';
foreach ( $categories as $cat ) {
$cat_url = get_bloginfo('url') . '/theme/' . $cat->slug;
$cat_output .= '
<dt>
<a href="'. $cat_url . '" title="' . __('Read articles of the category:', 'juiz') . ' &quot;'. $cat->cat_name .'&quot;">' . $cat->cat_name . '</a>
<span class="nb_articles">' . $cat -> category_count .' articles</span>
<a href="' . $cat_url . '/feed" title="' . __('Follow RSS feed of the category:', 'juiz') . ' &quot;'. $cat->cat_name .'&quot;" class="cat-rss"><i class="icon-feed"></i><span class="visually-hidden">RSS</span></a>
</dt>
<dd>' . $cat->category_description . '</dd>
';
}
$cat_output .= '</dl>';
echo $cat_output;
?>
</div><!-- .corps -->
</div><!-- .article.block -->
<?php
edit_post_link(__('Edit this page', 'juiz'), '<p>', '</p>');
comments_template();
?>
</div><!-- .part_main -->
</div><!-- .inside -->
</main><!-- .main_content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment