[Resolved] Sections and Custom Page Template

Home Forums Support [Resolved] Sections and Custom Page Template

Home Forums Support Sections and Custom Page Template

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #215739
    David

    Hi there,

    is it possible to hardcore sections into custom page template? Because my template does not work when sections are on.

    or

    Is is possible to tell my custom template file – “hey, wrap this HTML by section 1 divs – so this will look like first section; and another HTML code with section 2 divs – so that piece of page will look exactly like second section”. – this way is preferred

    Thank you! πŸ™‚

    #215807
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I’m not too sure what you mean?

    If you’re using a custom template file, you can definitely hard code your necessary HTML into the file itself.

    #215812
    David

    Ok, lets say that I will completely turn off sections in page where I want to use custom template.

    I need to hardcore this section (within wp_loop in custom page template file):
    section

    How can I do that when all stylesheets and other stuff for sections are gone because they are turned off?

    #215813
    Tom
    Lead Developer
    Lead Developer

    This topic might help: https://generatepress.com/forums/topic/set-a-page-template-to-use-sections/#post-187144

    It basically tricks the template into thinking sections are enabled, but then you add your own HTML sections.

    #215819
    David

    I’ve added this code into my theme’s functions.php:

    function zs_set_sections($post_id, $post, $update) {
    
        $template = get_post_meta($post_id, "_wp_page_template", true);
        if($template == "homepage.php") {
            add_post_meta($post_id, "_generate_use_sections", array("use_sections" => "true"), true);
        }
    
    }
    add_action( 'save_post', 'zs_set_sections', 10000, 3 );

    Now when I refresh/save/update my homepage in wpadmin, sections always stays on. I am not able to turn them off.

    And also when I hardcode my sections into template it doesn’t work πŸ™ . This is what I put into template (homepage.php):

    <div id="generate-section-2" class="generate-sections-container container2"><div class="grid-container grid-parent generate-sections-inside-container" itemprop="text">
    <div class="hide-on-mobile">
    <div class="grid-50 tablet-grid-50 mobile-grid-33">
     <div style="background-color: #f2f2f2; width: 100%; height: 253px">prve</div>
     </div>
    <div class="grid-50 tablet-grid-50 mobile-grid-33">
    <div style="background-color: #f2f2f2; width: 100%; height: 253px">prve</div>
    </div>
    </div></div></div>

    And it looks like that:

    Instead of correct version higher.

    #215945
    Tom
    Lead Developer
    Lead Developer

    Hmm, maybe we need to re-think what we’re doing here.

    So the problem is: When you add sections to your page and set the page template to your custom template – the sections don’t work. Correct?

    So, why use the custom page template in the first place? What’s it doing?

    #215969
    David

    Every page needs to have its custom page template because I am planning to implement custom fields later so client will be able to edit various areas within single page. And every page is different.

    Yes, that’s the problem – but only part of it.

    I cannot describe it by words very clearly so I will attach some pictures.

    I need to hardcode that area in red circle (just 100% width white box with 960px container in it is fine for me) into my template file. I thought it will be realizable through your sections plugin – just by copy-pasting raw section’s HTML code. But it’s not that easy πŸ™

    This is how my template looks now:

    #216106
    Tom
    Lead Developer
    Lead Developer

    Hmm, so why use Sections at all? If you’ll be adding custom fields, you won’t be able to use any of the Section options, making it kind of pointless to use it.

    I would just create the custom page templates to your liking with your HTML code and custom fields?

    #216138
    David

    Hi Tom,

    Yes thank you, now I got it πŸ™‚

    So let’s forget about sections and sorry about my bad explaining.

    I need to hardcore something like that into your theme (see picture bellow), how can I do it? Because when I put a 100% width div with any background color into <body>, it doesn’t wrap it completely.

    #216185
    Tom
    Lead Developer
    Lead Developer

    Basically, you need to apply this CSS to your page templates:

    .grid-container.container {
        max-width:100%;
    }

    The easiest way might be to use the Simple CSS metabox: https://wordpress.org/plugins/simple-css/

    #216202
    David

    After applying that CSS my whole page (within content) has been scaled to 100% width. I want to keep container width that is set in Customizer (mine is 960px).

    Width of this black rectangle has to be kept.

    #216291
    Tom
    Lead Developer
    Lead Developer

    Just so I’m clear, you’re wanting to entire page to be contained except for that one section, which you want to be 100% width?

    #216352
    David

    No, that’s not right. I want to split my entire page into more sections with box type fluid and inner box type contained with any background-color. Basically I just need to hardcode something like your sections plugin’s sections into page template.

    #216382
    Tom
    Lead Developer
    Lead Developer

    So then my code above sets everything to 100% width, then you need to wrap your sections like this:

    <div class="my-full-width-container">
        <div class="grid-container my-contained-inner-container">
            My content in here
        </div>
    </div>
    #216398
    David

    Yes, I already tried that solution before. The problem is that my whole page content is wrapped inside:

    <div id="page" class="hfeed site grid-container container grid-parent">
    <div id="content" class="site-content">*page content*</div></div>

    and when I put that code inside above divs (because default page.php template is wrapped by them in header.php and footer.php) it looks messy and it doesn’t work properly. So I always need to close those divs and put it after them.

    Then I need to create a new template files for my header.php and footer.php just because of removing 2 lines of code from each and I’m not sure if this is a good solution.

    How your sections plugin solved this problem?

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.