From 59811c1d8b051402d5e46b69ea762a1952202c38 Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@tetras-libre.fr> Date: Thu, 24 Jan 2019 16:13:52 +0100 Subject: [PATCH] Better category handling Fix #3 --- posts.php | 61 ++++++++++++++++++++++++++++++--------------- single_category.php | 5 ++++ 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/posts.php b/posts.php index 414ed21..914382b 100644 --- a/posts.php +++ b/posts.php @@ -1,32 +1,53 @@ <?php theme_include('header'); ?> <section class="content"> - + <?php + $title="Blog"; + if (preg_match('/category.*/',current_url())){ + echo "<p id='".current_url()."'></p>"; + while(categories()){ + echo "<p id='".category_url()."'></p>"; + if(category_url() == "/".current_url()){ + $title.=" - ".category_title(); + } + } + } + echo "<h1 style='text-align:center'>$title</h1>\n"; + ?> <?php if(has_posts()): ?> <ul class="items"> <?php posts(); ?> <li> - <h1> Dernier article </h1> - <?php include("single_article.php"); ?> - </li> - <li style="background:none"> - <h1> Catégories d'articles </h1> - <?php $i = 0; while(categories()): ?> - <?php $bg = sprintf('background: hsl(131, 6%%, %d%%);', round(50-((++$i / posts_per_page()) * 20))); ?> - <li style="<?php echo $bg; ?>"> - <?php include("single_category.php"); ?> - </li> - </li> - <?php endwhile; ?> - <li style="background:none"> - <h1> Articles précédents </h1> - <?php $i = 0; while(posts()): ?> - <?php $bg = sprintf('background: hsl(131, 6%%, %d%%);', round(50-((++$i / posts_per_page()) * 20))); ?> - <li style="<?php echo $bg; ?>"> + <h2> Dernier article </h2> <?php include("single_article.php"); ?> </li> - </li> - <?php endwhile; ?> + + <?php if (!preg_match('/category.*/',current_url())): ?> + <li id="<?php echo current_url();?>" style="background:none"> + <h2> Catégories d'articles </h2> + <?php $i = 0; while(categories()): ?> + <?php $bg = sprintf('background: hsl(131, 6%%, %d%%);', round(50-(($i / total_categories()) * 20))); ?> + <?php if(category_count() > 0 ):?> + <?php ++$i; ?> + <li style="<?php echo $bg; ?>"> + <?php include("single_category.php"); ?> + </li> + <?php endif; ?> + <?php endwhile; ?> + </li> + <?php endif; ?> + + <?php if(total_posts() > 1 || $title=="Blog"):?> + <li style="background:none"> + <h2> Articles précédents </h2> + <?php $i = 0; while(posts()): ?> + <?php $bg = sprintf('background: hsl(131, 6%%, %d%%);', round(50-((++$i / posts_per_page()) * 20))); ?> + <li style="<?php echo $bg; ?>"> + <?php include("single_article.php"); ?> + </li> + <?php endwhile; ?> + </li> + <?php endif?> </ul> <?php if(has_pagination()): ?> diff --git a/single_category.php b/single_category.php index 3d39ad5..cc2c974 100644 --- a/single_category.php +++ b/single_category.php @@ -7,4 +7,9 @@ <div class="contents"> <?php echo category_description(); ?> </div> + <footer> + <p> + Cette catégorie regroupe <?php echo category_count(); ?> <?php echo pluralise(category_count(), "article", "s")?>. + </p> + </footer> </article> -- GitLab