Roots Discourse

How do you create a custom header for a post type?

So let’s say I have a post type called projects (so the slug being"project")

If I want to have a page to show all the projects now I understand you have to go to Add New Page
and then create a page called projects with the url (site.com/projects) and then you make a file on /views called page-projects.blade.php where you would loop through all the projects. Then for a single project you create a php file called content-single-projects.blade.php etc… but lets say I wanted to have a unique header for that post type. Lets say i wanted to show a different header when loading content-single-projects.blade.php (meaning when i load a single project page) … Whats the best way to do that? would i have to create a project-header.blade.php?

I tried doing that but i didn’t work, but am i in the right track?

That’s more WordPress than it is Sage…

You’d use a function like the following to conditionally check which page you are on and display a different header:

@if (is_page( 'projects' ))
    <header>
        <!-- your project header -->
    </header>
@else 
    <header>
        <!-- your other header -->
    </header>
@endif

would that be a condition i use on app.blade.php? or head.blade.php?

You’d use it wherever you have your header. Sage default header is here:

You can use it in app but you should create a partial for each header then.

This topic was automatically closed after 42 days. New replies are no longer allowed.