Hello,
I am trying to output blog posts in date order whilst limiting other parameters such as the category.
Ultimately I want six blog posts listed in date order; however, I am always showing x1 video, x1 podcast, x1 blog and x3 news.
Whilst I have come close with a pure PHP way of achieving the goal, I've hit a snag whilst trying to output the Category Icon I have created. This appears to be ignoring the category array altogether?
PHP
- <section class="section-home-blog home-typography">
- <div class="wrapper">
- <?php
- $news = array();
- $news[] = perch_blog_custom([
- 'category' => array('podcast'),
- 'count' => 1,
- 'return-html' => false,
- 'skip-template' => true,
- 'raw' => true,
- ]);
- $news[] = perch_blog_custom([
- 'category' => array('video'),
- 'count' => 1,
- 'return-html' => false,
- 'skip-template' => true,
- ]);
- $news[] = perch_blog_custom([
- 'category' => array('blog'),
- 'count' => 1,
- 'return-html' => false,
- 'skip-template' => true,
- ]);
- $news[] = perch_blog_custom([
- 'category' => array('news'),
- 'count' => 3,
- 'return-html' => false,
- 'skip-template' => true,
- ]);
- function date_sort($a, $b) {
- return strtotime($b[0]['postDateTime']) - strtotime($a[0]['postDateTime']);
- }
- usort($news, "date_sort");
- print_r($news);
- foreach($news as $p):?>
- <div class="card">
- <div class="card__head">
- <perch:categories id="categories" set="blog">
- <img src="<?php echo $p[0]['image'];?>">
- </perch:categories>
- </div>
- <div class="card__body">
- <img src="<?php echo $p[0]['categories']['icon'];?>">
- <h1><?php echo $p[0]['postTitle'];?></h1>
- <h2><?php echo $p[0]['introText'];?></h2>
- </div>
- <perch:categories id="categories" set="blog">
- <p class="category"><perch:category id="catTitle" type="text"></p>
- </perch:categories>
- </div>
- <?php endforeach; ?>
- </div>
- </section>
The above is my current code.
Ideally it would be nice to build up some filters and then just do something like…
Appreciate any helped offered