I’m fairly new to Kirby and to php. Currently transitioned from using the Baseblog theme for my site at briansullan.com to using the latest Kirby Starterkit. I like that the latter allows me to insert a cover image for posts that appear on the main blog page, as shown in both entries I currently have active. But for the first post, I want to be able to display everything on the main page the way it looks on the subpage; these are typically short posts that won’t take up much real estate so I want to avoid having to go to a subpage. Had this ability in Baseblog through a dedicated video post template.
I know how to extend the amount of text shown and disable the Read More link, but not how to get the blockquote to display as styled and for the embed code to display. I have been going through the Kirby documentation and starting to understand but not quite there. Getting confused as to relationship between blueprints, snippets and templates and between article and blog templates. Also not sure if I need to make additional post types or maybe I could do what I need by adding options within the existing article type.
You can use an if statement like this for that bit where the text is rendered:
<div class="text">
<?php
// check if the article is the first article
if($article->is($articles->first())):
// echo text using kirbytext() method
echo $article->text()->kirbytext();
else: ?>
<p>
<?= $article->text()->kirbytext()->excerpt(50, 'words') ?>
<a href="<?= $article->url() ?>" class="article-more">read more</a>
</p>
<?php endif ?>
</div>
Thanks for the quick reply. That works! But for new entries how can I get the option to do that or keep the original post type with the excerpt and Read More link? Do I need to create a new post type or can I have an option added to the panel for the existing type?
Not quite sure what you are trying to achieve. If your articles are sorted by date in desc order, for example, the newest post will always be the first and thus will be displayed In full length, whereas all others will only have the excerpt show. So you would not have to change anything?
ok, sorry, it’s not just the first post, so I was not being clear. I really want the following options for how the entry appears on the main blog page for any new post:
- Show the full text or or just an excerpt with a Read More link
- Show embedded media
So this may require at least two different post types, unless the options can be provided for the current article type by adding options through the panel?
You can add options in the articles themselves, using checkboxes or select fields.
The only problem I see is embedded media, or rather, it depends on how you embed them. If you embed them together with text in a textfield, and you want to show the text but not the embedded media, you would have to filter these out.