-
YEAR93
Hi,
I’m have created a custom post type called Cases and I’m trying to use a GeneratePress Block Element → Content Template named Single Case Entry Content to control the layout of my single Case pages.
I’ve created a Block Element with:
- Element Type: Content Template
- Display Rule: Cases → All Cases
- The element is published
However, the Content Template does not seem to be applied to my single Case pages at all. After publishing and refreshing an existing Case single page, nothing changes.
My Case single pages are still displaying the normal/default content layout.
I also have a separate Block Element → Hook for the Case hero, which is set to
after_headerwith the location Cases → All Cases, and that element is working correctly.What I’m ultimately trying to achieve is to use the Content Template to create a consistent layout for all Case single pages, while also displaying and styling the regular Gutenberg post content of each Case.
Could you please take a look and let me know why the Content Template is not being applied to my Case single post pages, or if there is another setting I need to enable for a custom post type?
Thanks!
-
Alvind
Hi there,
The issue comes from the custom
single-case.phpfile in your child theme.That template loads the Case content directly using:
get_template_part( 'content', 'case' );This bypasses the GeneratePress function that allows a Content Template Element to replace the default content.
In
single-case.php, change that line to:generate_do_template_part( 'case' );This will continue using your existing
content-case.phpfile whenever no Content Template applies, while allowing the Content Template Element to take over when its display conditions match.Alternatively, if the custom
single-case.phpandcontent-case.phptemplates are no longer required, you can remove them from the child theme and let GeneratePress use its standard single-post template.The separate Page Hero works because its
after_headerhook is outside this template-part handling. -
YEAR93
Hi,
I changed the line in my single-case.php according to your instructions and replaced:
get_template_part( 'content', 'case' );with:
generate_do_template_part( 'case' );The Single Case Page Hero is still showing correctly, but everything after the Page Hero is empty.
What I actually want is for the entry content of the Case to be displayed dynamic inside the container I created in my GeneratePress Element called “Single Case Entry Content”.
Could you explain how I can get the Case entry content to render inside that Element/container, while still allowing the Content Template Element to take over when its display conditions match?
At the moment, the Page Hero works, but there is no content being output underneath it.
Thanks!
-
You’ve changed
get_template_part( 'content', 'case' )toget_template_part('case' ), however, Alvind asked to change it togenerate_do_template_part( 'case' );
https://app.screencast.com/W8JtjVUutz521 -
YEAR93
Hi,
Perfect, it works now. Thank you for your help!
I have one more question. There seems to be an unexplained amount of space between my Single Case Page Hero element and my Single Case Entry Content element. View attached screenshot.
I would like to remove this space so that the Entry Content starts directly after the Hero section.
Do you know what could be causing this spacing and how I can remove it?
Thanks again for your help!
-
Alvind
The spacing is coming from two places.
First, this custom CSS moves the Page Hero upward by the height of the header:
.single-case-hero { top: calc(-1 * var(--site-header-height)); }Because the Hero uses relative positioning, this changes its visual position but leaves its original 76px of space behind.
Please replace that rule with:
.single-case-hero { top: auto; margin-top: calc(-1 * var(--site-header-height)); } @media (max-width: 768px) { .single-case-hero { margin-top: 0; } }Using a negative margin moves the Hero and also allows the Entry Content to follow it without leaving the header-height gap.
Your Single Case Entry Content Element also has 80px of top padding on its outer Container, with 60px on mobile. You can reduce or remove that padding in the Container’s Spacing settings if you want the post content to sit closer to the Hero.
-
YEAR93
Thank you, this is exactly what I was looking for!
-
Alvind
You’re welcome!
- You must be logged in to reply to this topic.