Separate home page and blog (loop) page in theme (developing a new theme)

Post Reply
shevina
Jr. Bludit
Posts: 6
Joined: Fri Dec 24, 2021 5:59 pm
Been thanked: 1 time
Contact:

Hi guys,
I'm developing a new theme for bludit, this theme is based on my html template.
I can't figure it out how to implement a way that my theme show's a static page in front and have a separate page for blog to show posts.

In fact front page is working but can't find a way for blog. Only way I can show the posts is to set "blog.php" for "home".

You can view my original template from here.
And link to my bludit testing website is here.

the code I use in my "index.php":

Code: Select all

    <?php
    if ($WHERE_AM_I == 'page') {
        include(THEME_DIR_PHP . 'page.php');
    } elseif ($WHERE_AM_I == PATH_ROOT . 'blog') {
        include(THEME_DIR_PHP . 'blog.php');
    } elseif ($WHERE_AM_I == 'home') {
        include(THEME_DIR_PHP . 'home.php');
    }
    ?>
With the code above my front page loads but for "blog" I get the page not found (404) error. If I create a blog page as static it won't help as it shows the page created by Bludit not my "blog.php"

hint: I'm not a php developer so I may miss something :)

Any suggestion?
Website - my parallel life :)
Github Repo - my github land
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Very nice theme!

You can do it as follows:
  1. Create a static page.
  2. Set the static page as "Homepage" at "Settings" > "General" at the tab "Advanced" at "Predefined pages" (with this the URL filter /blog/ on the same page is activated).
  3. Create a static page with the title "Blog".
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
shevina
Jr. Bludit
Posts: 6
Joined: Fri Dec 24, 2021 5:59 pm
Been thanked: 1 time
Contact:

Thanks Edi, that worked nicely for blog.

But now I have other issues, first my menu messed up: got two menu Items pointing to home. The page created by Bludit and the Item I coded for pointing to root of web site. I think I can override this by removing the item from navbar.php and letting the pages only appear then change the order of the pages to make homepage become the first one.

But this will leads to a problem if anyone wanted to use theme only for blog will face a problem in menu that nothing is pointing to the root (base url) in the menu.

Second issue is the home page. Home page is an empty page created by Bludit, How can I make it a custom page that shows page that I wrote specific for HOME, not default page?

Now I reached Here so far by development (Theme) :)

Thanks.

Any more suggestion?
Website - my parallel life :)
Github Repo - my github land
Bernie
Ssr. Bludit
Posts: 11
Joined: Wed Sep 15, 2021 12:37 pm
Been thanked: 7 times

Write a module with which you can put your content on your homepage.
shevina
Jr. Bludit
Posts: 6
Joined: Fri Dec 24, 2021 5:59 pm
Been thanked: 1 time
Contact:

Bernie wrote: Sun Dec 26, 2021 12:35 am Write a module with which you can put your content on your homepage.
Thanks Bernie, sorry to bother but I'm not very familiar with php or Bludit, you mean module in the theme or a separate plugin? Is there any example (theme)?
Website - my parallel life :)
Github Repo - my github land
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

shevina wrote: Sat Dec 25, 2021 10:55 am But now I have other issues, first my menu messed up: got two menu Items pointing to home. The page created by Bludit and the Item I coded for pointing to root of web site.
What do you mean with root? Should the navigation be linked with a hard coded page?
Second issue is the home page. Home page is an empty page created by Bludit, How can I make it a custom page that shows page that I wrote specific for HOME, not default page?
If your home page has for example the title "Mainpage" and the slug mainpage (at "Options" > "SEO" > "Friendly URL") you can use the following in the file index.php of the theme:

Code: Select all

if ($WHERE_AM_I == 'page') {
   if ($page->slug() == "mainpage") {
       include(THEME_DIR_PHP.'mainpage.php');
   }
      else {
       include(THEME_DIR_PHP.'page.php');
   }
}
else {
   include(THEME_DIR_PHP.'home.php');
}
mainpage.php will be in this cas the template of your home page.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
Bernie
Ssr. Bludit
Posts: 11
Joined: Wed Sep 15, 2021 12:37 pm
Been thanked: 7 times

shevina wrote: Sun Dec 26, 2021 9:55 am
Bernie wrote: Sun Dec 26, 2021 12:35 am Write a module with which you can put your content on your homepage.
Thanks Bernie, sorry to bother but I'm not very familiar with php or Bludit, you mean module in the theme or a separate plugin? Is there any example (theme)?
This would be a solution to write content directly into the root.

I have read through your first post again. Your problem is not to put content on the home page, but to create a separate page with a loop of posts.

This is possible in Bludit.

1. Change the code on the index.php.

Code: Select all

  <?php
    if ($WHERE_AM_I=='home') {
    	include(THEME_DIR_PHP.'home.php');
    } elseif ($page->template()) {
    	$file = THEME_DIR_PHP.$page->template().'.php';
      if (file_exists($file)) {include($file);} else {include(THEME_DIR_PHP.'page.php');}
    } else {
      include(THEME_DIR_PHP.'page.php');
    }
  ?>
2. Your blog.php goes into the folder "php" of your theme.

3. Now edit your page blog.
In the field under Options --> Advanced --> Template write "blog" and save it.
Now you have assigned the template blog.php to the page /blog.
shevina
Jr. Bludit
Posts: 6
Joined: Fri Dec 24, 2021 5:59 pm
Been thanked: 1 time
Contact:

Bernie wrote: Sun Dec 26, 2021 12:56 pm 1. Change the code on the index.php.

Code: Select all

  <?php
    if ($WHERE_AM_I=='home') {
    	include(THEME_DIR_PHP.'home.php');
    } elseif ($page->template()) {
    	$file = THEME_DIR_PHP.$page->template().'.php';
      if (file_exists($file)) {include($file);} else {include(THEME_DIR_PHP.'page.php');}
    } else {
      include(THEME_DIR_PHP.'page.php');
    }
  ?>
2. Your blog.php goes into the folder "php" of your theme.

3. Now edit your page blog.
In the field under Options --> Advanced --> Template write "blog" and save it.
Now you have assigned the template blog.php to the page /blog.
Thanks Bernie for the example (and clean code).
I couldn't make it work by template() function, but it worked if I hardcoded the template name.

Edi wrote: Sun Dec 26, 2021 12:17 pm
If your home page has for example the title "Mainpage" and the slug mainpage (at "Options" > "SEO" > "Friendly URL") you can use the following in the file index.php of the theme:

Code: Select all

if ($WHERE_AM_I == 'page') {
   if ($page->slug() == "mainpage") {
       include(THEME_DIR_PHP.'mainpage.php');
   }
      else {
       include(THEME_DIR_PHP.'page.php');
   }
}
else {
   include(THEME_DIR_PHP.'home.php');
}
mainpage.php will be in this cas the template of your home page.
Thanks a lot Edi, this worked.
and for the root I meant the home page or DOMAIN_BASE.

I did it by this: (needs more cleaning)

Code: Select all

    if ($WHERE_AM_I == 'page') {
        // check for front page
        if ($page->slug() == 'front') {
            include(THEME_DIR_PHP . 'front.php');
            include(THEME_DIR_PHP . 'frontFooter.php');
        } else {
            include(THEME_DIR_PHP . 'page.php');
            include(THEME_DIR_PHP . 'footer.php');
        }
        // load the blog.php
    } else {
        include(THEME_DIR_PHP . 'blog.php');
        include(THEME_DIR_PHP . 'footer.php');
    }

Website - my parallel life :)
Github Repo - my github land
Post Reply