File/folder structure for putting weblog on homepage

I started building my first personal website with Kirby a few days ago. I’m setting the homepage to be my weblog, and I’m following along with the instructions here (Creating a Kirby-powered blog | Kirby CMS).

However, the example in the link above is setting up a weblog on a separate page, not the homepage itself. If I want to make the homepage the weblog, should I still put all the article folders in the Content folder, or should they all go in the parent folder for where all the Kirby files and directories are located? (In my case, the shared server I’m using has everything in a folder called Public_HTML, and Content is a child folder in there.)

Furthermore, are there other things I should do differently from the example in the link? For one thing, I’m assuming my homepage template (default.php) will work in place of the blog.php you create in the link, but I wasn’t sure if there are other things I need to consider as well.

If you need more details from me, let me know. Thanks!

If you want the homepage to be the blog page, then your blog posts would become subfolders of home.

You can, however, name the home folder blog if you want, you just need to tell Kirby in your config by setting home to blog: home | Kirby CMS.

Structure would then look like this:

content/
  -- blog/  --instead of home
      -- post-1
      -- post-2
  -- error
  -- site.txt

Thanks. I left the naming alone, and created a test folder/article in the home folder. However, the post is not displaying on my homepage.

Here’s how my content folder is arranged:

content/
– 1_testpage1
– 2_testpage2
– 3_testpage3
– 4_testpage4
– error
– home
– 1_test-post-1
– test_post_1.txt
– home.txt
– site.txt

My default template is default.php in the primary folder, where the content folder is located. Home.txt just contains the UUID, and site.txt just has “Title: test” in it - I think I was messing with that earlier, so I’m not sure if I even need that file at this point or if I need to modify it.

Also - in case this context matters - I’m modifying the default theme that installs with Kirby. I installed it through Softaculous in CPanel, so I wasn’t aware of the blank template that’s also available. Thought I’d mention that in case there may be some conflicts between the default theme and my changes that I’m not aware of.

Hope that helps give a better picture of my arrangement, but if not, let me know what other info you need and I’ll happily provide it (such as code in my pages and snippets, I wasn’t sure if you’d need that info just yet).

Could you please post the code you are using to output the children of home in your default.php template?

Default.php looks like this:

<?php snippet('header') ?>

  <main>    
   <?php snippet('article') ?> 
  </main>
  
<?php snippet('footer') ?>

  </body>
</html>

I haven’t routed anything to/from files in the Home folder yet because I was just working on the default.php template itself, and then making folders/files for the children pages in the Content folder. The snippets I reference above are in the Snippets folder, and if you need the code for those, I can provide it.

FYI, the first <body> tag is in the Header snippet.

Yes, of course, please do, because that code in the template doesn’t tell me anything.

Sure, sorry about that. Header looks like this (I’m omitting <meta name> and <meta property> info for brevity, along with my <topnav> and CSS links:

<!DOCTYPE html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <title><?= $page->title() ?> | <?= $site->title() ?></title>
  </head>

  <body>
    
    <div class="topnav">
    </div>

The Article snippet looks like this:

<?php foreach($page->children()->listed()->flip() as $article): ?>

<article>
  <?= $page->text()->kirbytext() ?>
  <time><?= $page->published()->toDate('d.m.Y') ?></time>
</article>

<?php endforeach ?>

And the Footer looks like this:

<footer>
	<div class="footer">
		<p>© copyright info</p>		
  </div>
</footer>

Hm, but that looks about ok, provided your home folder has at least one child folder and that child folder has a text field and a published field. But it doesn’t render anything?

But I’m a bit confused about this sentence, no idea what you mean.

Templates live in /site/templates

Home folder does have one child folder (the folder for my test post, which contains the test .txt file). That .txt file does have a text field, but not a published field. This is the content of the test_post_1.txt file:

Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

So when I go to my homepage, the page is formatted correctly based on my snippets and CSS, but the page itself has nothing other than those snippet elements.

Ah, maybe this is where my problem is. My default.php file is in the main folder with my Kirby installation - it’s called public_html. So that folder’s structure looks like this:

public_html/

404.shtml
– assets
– cgi-bin
composer.json
– content
default.php
favicon.ico
index.htm.bak
index.php
– kirby
logo-imh.svg
– media
phpinfo.php
README.md
robots.txt
– site

I thought the default.php template was here by default, as I can’t recall moving it from another folder, but maybe I’m mistaken.

There it won’t do anything

Check out our Plainkit or Starterkit for what a basic and correct folder structure looks like in Kirby.

I’m sorry, it seems there are two default.php files - the one I’m editing is indeed in the site/templates folder. The one that’s in the parent folder is the stock template from, I assume, the Starterkit theme.

I assume it’s okay for me to delete the default.php that’s in the parent folder, since that does not have my changes. Perhaps I moved it there by mistake or something.

Do you only have the default.php in site/templates?

There are two default.php templates:

  1. In site/templates, which is what I have been editing.

  2. In the public_html folder, which seems to have the stock code for the Starterkit theme.

I will keep #1, and delete #2.

My templates folder has these files:

  • page1.php (I changed the name here, so they won’t appear in alpha order)
  • default.php
  • feed.json.php
  • page 2.php
  • page 3.php

EDIT: I don’t have a home.php template - I assume the default.php should work fine as documentation indicated, correct? Or do I need to make a home.php template since I have a home.txt file?

No, the default.php template kicks in whenever there is no dedicated template (i.e. template with the same name as the content txt file)

Overlooked it earliert, but the problem with your code is, that inside the loop you use $page instead of $article. $page refers to the current page, i.e. in this case the home page.

Ah, okay. So should I replace ALL instances of $page with $article instead, or just the ones inside the <article> tag? The php line at the top should be the line for flipping the order of the posts inside the folder so the most recent one shows at the top of the page, but let me know if I screwed that one up too.

The ones inside the foreach loop

I’m still not seeing my test post show up, let me confirm that I’m understanding your instructions right:

  1. Replace $page with $article in the foreach loop - so it should look like this instead?

<?php foreach($article->children()->listed()->flip() as $article): ?>

  1. Earlier in the thread, you said:

Hm, but that looks about ok, provided your home folder has at least one child folder and that child folder has a text field and a published field.

I had a follow-up question to that, but I don’t think it was answered:

Home folder does have one child folder (the folder for my test post, which contains the test .txt file). That .txt file does have a text field, but not a published field.

Do I need to add a published field to my .txt file?