I would like to add the latest blog excerpt to a home page and link to the full post. Could you point me in the direction where I could find out how to do this?
Many thanks.
Yes, I have read that. It just describes how to create a blog and articles not to say have a blog excerpt on a different page.
With page('blog')
you get the blog page, the rest is the same as on the original page.
I have used what I have which is a bit different to the code for creating a blog and it does not work. I get the error message, This page is currently offline due to an unexpected error…
The basic code that I am using for blog.php is:
<?php foreach ($articles as $article): ?>
<h1 class="blog-title"><?= $article->title()->link() ?></h1>
<time class="blog-date"><?= $article->date()->toDate("d F Y")
<?= $article
->text()
->excerpt(400, false)
->kirbytext() ?>
<?php endforeach; ?>
But that doesn’t tell us what you are trying in home.php… You are using $articles
here, which is probably defined in your home.php controller as $page->children()->listed()
.
In the home template, you would replace this with page('blog')->children()->listed()
.
You are using $articles
here, which is probably defined in your home.php controller as $page->children()->listed()
.
No, I don’t have that. What I have is the code that I provided, basically. That’s it.
I’m sorry, but this $articles
variable must be defined somewhere, it doesn’t exist out of the blue.
But in any case, if in your home.php template you define
$articles = page('blog')->children()->listed();
foreach ($articles as $article) {
// you can do the same as in your blog template
}