Editing page parts in templates


Hello,

I'm a bit confused with how to make page templates with Beans and was hoping I could find some help here.

On certain pages/types of pages I need the content header different from the rest of the pages (so, not the header.php but things like the post title and post header data.) I figured there are a couple ways I can do this, but the easiest might be to simply make a page template (template-PageCategory.php) that I will manually apply to certain types of pages within the Wordpress page editing menu.

The problem lies within the template - I entered in the custom html for the header, but when I try to display the content nothing renders on the page. Neither <?php the_content();?> nor <?php beans_post_content();?> display anything.

However, if I put in <?php beans_loop_template(); ?> or <?phpbeans_content_template( );?> it does display the page content... But also the page title.

So, I tried leaving that but removing the page title in the functions.php file, however I have so far been unable to figure out how to create a function to remove the title only on pages with the template.

Any advice on how to best go about this would be greatly appreciated. Thanks for your time.


Hello Caroline,

If all what you want to do is to remove the page title on some specific pages, maybe it's not necessary to create a specific page template.

So, for instance, if you want to remove title for a given list of pages, you could add something like this in your functions.php.

add_action( 'wp', 'myprefix_custom_output' );

function myprefix_custom_output() {

  // When the pages with a post_title of "contact", "hello" and "welcome" is being displayed.
    if ( is_page ( array ('contact','hello','welcome') ) {

        // Remove Post Ttile.
        beans_remove_action( 'beans_post_title' );

    }

}

Another suggestion : I would recommend you to read this.

Hope it helps.

Mathieu


Not quite, as I noted the pages still need to have the title, but displayed differently and with additional data that the other pages won't/don't have.

I figured a page template would be the cleanest and simplest way to achieve this and would allow for dynamic adding of pages with the unique format - since the list of pages that need that special formatting will likely grow in the future.


Hi Caroline,

If your modifications apply to multiple pages, you want to avoid creating multiple templates with the same modification (DRY) and rather move it in a shared file or in functions.php like Mathieu correctly suggestted. Everything on the page can be modified using hooks in Beans so don't have to override tempate file.

Let us know exactly what you layout should be (aka what you need to modify) and on which pages and we will gladly help you with that 🙂

Thanks,


Hi Thierry,

Well, I'm trying to move around the page title and add some text below it, and have a large background image - which could be the "featured image" or something manually inserted. All of these things would be specific for the page, but would apply to multiple pages. I also want them to be full-page width and not bound by the content's container div.

It's really similar to how Chi'lantro does the page title banner here: http://www.chilantrobbq.com/catering/ They have the site header with navigation, then below that a large banner specific to that page, with the page title and text on top. Then the actual page content below.

Edited to add: I copied the code Matthieu shared to remove the page titles however I get a syntax error for the line:

 if ( is_page ( array ('contact','hello','welcome') ) {

I get the error when I use the original code as well as when I edited the page titles to reflect which ones I wanted to change.

Thanks, Caroline


Hi Caroline,

Chi'lantro has multiple blocks on the page. To achieve such layouts, I would advise you to looking into using fields in the backend to store data and output it in the front end the way you want it. Lots of Beans users are using Carbon Fields or ACF for that.

Happy coding,

Write a reply

Login or register to write a reply, it's free!