Roots Discourse

Wrong Class Name to body in front page

Hello, I don’t know if this issue is caused by sage or blade but I can’t found the cause.
I have 2 simple page. One is set like “homepage” and another like “blog”.
The problem is when the body_class() is invoked in home page, the body has wrong class name. In fact he has class name “blog” and not “home” or “home-page”.

Anyone have an idea? Thank you!

1 Like

Sounds like you have your reading settings set incorrectly. There’s nothing in the theme that would be causing the class to be wrong — this is coming straight from the WP settings.

ok @benword thank you. I’ll try to figuring out the cause :+1:

I realize it’s been a while, but did you ever determine the cause of this? I’m having the exact same issue while trying to rebuild my Sage 8 theme in Sage 9, and have no idea why.

How can the exact same site, with the exact same settings have this problem in Sage 9 but not 8?

There were some fairly big changes between 8 and 9, not the least of which were Blade templating and a very early version of the Composer system in the form of Sage’s data filters. I don’t know for certain what’s causing the problem, because I’ve never run into this problem, but I would guess it has something to do with this: In Sage 9, there’s a filter that runs on the body classes to modify them so they can be used to hook up to the Blade stuff and pass data around. It’s possible that something in there is causing you to get classes you don’t expect (or not get classes you do expect).

Thanks for the reply. I’ve actually looked into filters.php, but since haven’t made any changes there, I’m not sure why / how it could be causing me grief? Also, I have a couple of other Sage 9 sites, with the exact same setup, but they have the appropriate classes.

My upgrade process has been the following:

  • Install Sage 9 theme, alongside Sage 8 theme
  • 1 file at a time, copy select code over from Sage 8 theme,
    • ensuring php templates are properly converted to blade and placed in the proper locations
    • ensuring to keep Sage 9’s versions of code / functions where similar

Any ideas on what could possibly be throwing this filter off, if that’s what’s happening? I’ve looked everywhere and have compared this theme to one of my working Sage 9 themes countless times, and can’t find any inconsistencies / conflicts between them that could be throwing anything off. Is there anything else I can provide to help narrow this down?

Ah okay, I think I found the offending code… It seems to be related to the following line of code I had in my front-page.blade.php:

@php query_posts('showposts=3') @endphp

That line of code is part of a snippet that shows sticky posts in a section of the home page. For some reason having it in changes the body class to blog, but commenting it out sets it back to home, like it should be.

Since this issue doesn’t happen in the Sage 8 version of my front-page.php there must be some kind of incompatibility with query_posts() and Sage 9 / blade that’s causing this. I haven’t had a change to look into it yet, but I’ll update this when I find a solution.