How can I display a simplified/shortened list of blog posts? #1009
Answered
by
pftnhr
henryVr7
asked this question in
Ask a question
-
I can use the tag [blogpages] to create a list of all posts. However, I would like a shortened list of the last 5. Is there a smart way to do this? And: Is there also a tag to display the content of the latest blog post (or everything up to the more tag)? Background: I would like to always have the latest article on a (start) page and an overview of the others underneath. |
Beta Was this translation helpful? Give feedback.
Answered by
pftnhr
Jan 30, 2025
Replies: 0 comments 13 replies
-
I haven't checked it but this is how I think it should work (Please note the comments in the code.): <?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<?php if ($this->yellow->page->get("blogWithFilter")): ?>
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php endif ?>
<?php $pages = $this->yellow->page->getPages("blog")->paginate($this->yellow->system->get("blogPaginationLimit")) ?>
<?php $postCount = 0; // Set $postCount to 0 ?>
<?php foreach ($pages as $page): ?>
<?php $postCount++; // Increase $postCount with each iteration ?>
<?php $page->set("entryClass", "entry") ?>
<?php if ($page->isExisting("tag")): ?>
<?php foreach (preg_split("/\s*,\s*/", $page->get("tag")) as $tag) { $page->set("entryClass", $page->get("entryClass")." tag-".$this->yellow->lookup->normaliseClass($tag)); } ?>
<?php endif ?>
<?php if ( $postCount === 1 ) { // iterate over the $postCount and show post content only if $postCount is 1 ?>
<div class="<?php echo $page->getHtml("entryClass") . ' ' . $postCount ?>">
<div class="entry-title"><h1><a href="<?php echo $page->getLocation(true) ?>"><?php echo $page->getHtml("title") ?></a></h1></div>
<div class="entry-meta"><p><?php echo $page->getDateHtml("published") ?> <?php echo $this->yellow->language->getTextHtml("blogBy") ?> <?php $authorCounter = 0; foreach (preg_split("/\s*,\s*/", $page->get("author")) as $author) { if (++$authorCounter>1) echo ", "; echo "<a href=\"".$this->yellow->page->getLocation(true).$this->yellow->lookup->normaliseArguments("author:$author")."\">".htmlspecialchars($author)."</a>"; } ?></p></div>
<div class="entry-content"><?php echo $this->yellow->toolbox->createTextDescription($page->getContentHtml(), 0, false, "<!--more-->", "<a href=\"".$page->getLocation(true)."\">".$this->yellow->language->getTextHtml("blogMore")."</a>") ?></div>
</div>
<?php } else { // else, only show title and meta-data ?>
<div class="<?php echo $page->getHtml("entryClass") . ' ' . $postCount ?>">
<div class="entry-title"><h1><a href="<?php echo $page->getLocation(true) ?>"><?php echo $page->getHtml("title") ?></a></h1></div>
<div class="entry-meta"><p><?php echo $page->getDateHtml("published") ?> <?php echo $this->yellow->language->getTextHtml("blogBy") ?> <?php $authorCounter = 0; foreach (preg_split("/\s*,\s*/", $page->get("author")) as $author) { if (++$authorCounter>1) echo ", "; echo "<a href=\"".$this->yellow->page->getLocation(true).$this->yellow->lookup->normaliseArguments("author:$author")."\">".htmlspecialchars($author)."</a>"; } ?></p></div>
</div>
<?php } ?>
<?php endforeach ?>
<?php $this->yellow->layout("pagination", $pages) ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?> |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are some settings, see yellow-blog.
You can set the
BlogPaginationLimit
to whatever value yo…