From f76f1ff183b753a7d08c706407049936acb06eb0 Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@tetras-libre.fr> Date: Fri, 14 Jul 2017 18:45:50 +0200 Subject: [PATCH] =?UTF-8?q?meilleur=20pr=C3=A9sentation=20des=20articles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- article.php | 6 +++--- css/reset.css | 4 ++-- functions.php | 16 +++++++++++++++- posts.php | 24 +++++------------------- single_article.php | 16 ++++++++++++++++ 5 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 single_article.php diff --git a/article.php b/article.php index 0f21a6c..09cb97b 100644 --- a/article.php +++ b/article.php @@ -1,15 +1,15 @@ <?php theme_include('header'); ?> <section class="content wrap" id="article-<?php echo article_id(); ?>"> - <h1><?php echo article_title(); ?></h1> + <h1><?php echo article_img(article_slug());?><?php echo article_title(); ?></h1> <article> - <?php echo article_markdown(); ?> + <?php echo article_html(); ?> </article> <section class="footnote"> <!-- Unfortunately, CSS means everything's got to be inline. --> <p>Article numéro: <?php echo article_number(article_id()); ?>, <?php echo count_words(article_markdown()); ?> mots <?php if(comments_open()): ?>, - <?php echo total_comments();?> <?php echo pluralise(total_comments(), "commentaire", "s") ?> pour le moment.<?php endif; ?> <?php echo article_custom_field('attribution'); ?></p> + <?php echo total_comments();?> <?php echo pluralise(total_comments(), "commentaire", "s") ?>.<?php endif; ?> <?php echo article_custom_field('attribution'); ?></p> </section> </section> diff --git a/css/reset.css b/css/reset.css index e7bac6e..c7db331 100644 --- a/css/reset.css +++ b/css/reset.css @@ -159,12 +159,12 @@ img.picture{ .odd{ float:left; - margin: 0% 2% 0% 0%; + margin: 0% 10% 0% 0%; } .even{ float:right; - margin: 0% 0% 0% 2%; + margin: 0% 0% 0% 10%; } diff --git a/functions.php b/functions.php index e7333f4..f25562a 100644 --- a/functions.php +++ b/functions.php @@ -11,7 +11,7 @@ function numeral($number, $hideIfOne = false) { return ''; } - $ext = ((abs($number) % 100 < 21 and abs($number) % 100 > 4) ? 'th' : (($test < 4) ? ($test < 3) ? ($test < 2) ? ($test < 1) ? 'th' : 'st' : 'nd' : 'rd' : 'th')); + $ext = $number == 1 ? 'er' : 'ème'; return $number . $ext; } @@ -97,3 +97,17 @@ function social_list($properties) { function total_articles() { return Post::where(Base::table('posts.status'), '=', 'published')->count(); } + +function article_img_url($slug){ + return '/img/blog/'.$slug.'.png'; +} + +function article_has_img($slug){ + return file_exists('.'.article_img_url($slug)); +} + +function article_img($slug){ + if(article_has_img($slug)){ + echo '<img class="picture odd" src="'.article_img_url($slug).'" />'; + } +} diff --git a/posts.php b/posts.php index f1fbfe3..b216c03 100644 --- a/posts.php +++ b/posts.php @@ -6,28 +6,14 @@ <ul class="items"> <?php posts(); ?> <li> - <article class="wrap"> - <h1> - <a href="<?php echo article_url(); ?>" title="<?php echo article_title(); ?>"><?php echo article_title(); ?></a> - </h1> - - <div class="content"> - <?php echo article_html(); ?> - </div> - - <footer> - Posté <time datetime="<?php echo date(DATE_W3C, article_time()); ?>"><?php echo relative_time(article_time()); ?></time> par <?php echo article_author('real_name'); ?>. - </footer> - </article> + <h1> Dernier article </h1> + <?php include("single_article.php"); ?> </li> + <h1> Articles précédents </h1> <?php $i = 0; while(posts()): ?> - <?php $bg = sprintf('background: hsl(215, 28%%, %d%%);', round(((++$i / posts_per_page()) * 20) + 20)); ?> + <?php $bg = sprintf('background: hsl(132, 22%%, %d%%);', round(((++$i / posts_per_page()) * 20) + 20)); ?> <li style="<?php echo $bg; ?>"> - <article class="wrap"> - <h2> - <a href="<?php echo article_url(); ?>" title="<?php echo article_title(); ?>"><?php echo article_title(); ?></a> - </h2> - </article> + <?php include("single_article.php"); ?> </li> <?php endwhile; ?> </ul> diff --git a/single_article.php b/single_article.php new file mode 100644 index 0000000..9fc0650 --- /dev/null +++ b/single_article.php @@ -0,0 +1,16 @@ +<article class="wrap"> + <h2> + <a href="<?php echo article_url(); ?>" title="<?php echo article_title(); ?>"><?php echo article_img(article_slug());?><?php echo article_title(); ?></a> + </h2> + + <div class="contents"> + <?php echo article_description(); ?> + </div> + + <footer> + <p>Article numéro: <?php echo article_number(article_id()); ?>, <?php echo count_words(article_markdown()); ?> mots <?php if(comments_open()): ?>, + <?php echo total_comments();?> <?php echo pluralise(total_comments(), "commentaire", "s") ?>.<?php endif; ?> <?php echo article_custom_field('attribution'); ?></p> + Posté <time datetime="<?php echo date(DATE_W3C, article_time()); ?>"><?php echo relative_time(article_time()); ?></time> par <?php echo article_author('real_name'); ?>. + </footer> + </article> + -- GitLab