Roots Discourse

Custom page-header.php?

I want to have a custom page-Header for the blog listing page (not front page).

I created a custom page called page-logbook.php and a custom page Header under templates called page-header-logbook.php

I call it in page-lookbook.php with this line:

<?php get_template_part('templates/page', 'header-logbook'); ?>

but nothing happens. What am I/could I be doing wrong?

why not a php include for the header?

@pelayo_mao thanks for your response. While that would be a solution I thought the roots way is how I tried to do it!?

An idea, try (‘templates’ . ‘page-header-lookbook’)

Not shure of this. Im not expert.
probably reading documentarion
again is what you need

Have you made sure page-logbook.php is being used as the template? The get_template_part code looks fine.

I just double checked that the correct page template is in place. I also tried<?php get_template_part('templates/page-header-logbook'); ?> which didn’t do the trick. I think I’ll play with a fresh local installation on XAMPP and see if it’s the same there.

It’s really weird. I tinkered a bit with a fresh localhost install. If I replace the string “logbook” with another string, it works, e.g.

base-page-test.php
page-test.php (with template name Test Template, of course)
templates/page-header-test.php

Working on a new project, I ran into the same issue again (didn’t solve the former, btw). It seems this is only the case with the page-header for the blog. Can anybody confirm this? The file structure basically works as I’m using individual background-images per page, it’s just an issue with the page-header for the blog.

As I have a limited number of pages, it’s not a big deal to use a custom page-header per page and modify the default page-header as needed for the blog. However, I think this is not the way things should work…

I know it’s probably not this but are you using adblock?

I run into problems with it sometimes, last one was advenced custom field named ‘reklama’ (advertise) and this bastard was blocking it somehow.

It’s worth trying.

Thanks, I_dudzic, no, it’s not adblocking and it’s not utilizing a name which is related to spam. And as I said it works perhaectly on pages, categories and tags.

Could be that if you’re copying the code from somewhere there may be some non UTF-8 characters??

Nope, but I finally solved the riddle!

Actually it’s logical…

Here’s the solution:

  1. Create/select a page in your backend which the blog will be associated with, for ease of explanation, let’s name the page “Blog
  2. copy base.php to base-index.blog.php
  3. copy index.php to index-blog.php
  4. Now you can edit the first line to use a custom page-header with it (‘header-blog’) and create a custom pageheader by copying page-header.php to page-header-blog.php

It wouldn’t work with just modifying index.php and creating a custom page header for all the other pages as the index.php’s page-header would be pulled for archive pages as well, so one had to create a custom page header for every category or tag if that’s noit desired.

Hope it helps someone else.