• Resolved jeflopo

    (@jeflopodev)


    I would like to be able to create different templates for my Posts page. One with sidebar and a list view, another one displaying a grid view for the query block, and another one with a list view but no sidebar.

    I have created two pages: “Homepage” & “Posts page”.
    Then, I’ve respectively set the “Your hompage displays” in the Reading Settings page.

    By doing that, If I edit the “Posts page” and try to change the template, it says that “The posts page template cannot be changed”:

    But If we go to the “Quick edit” of the “Posts page” page. We can see the “Template” dropdown that, in theory, it let us select a registered custom template.

    But this way, WordPress keeps using the “home.html” template file (as is defined by the template hierarchy). And doesn’t really make use of that custom template that I just selected (it uses home.html instead).

    By searching on Google about that, I found some people recommending to leave blank the “Posts page” dropdown option of the “Your hompage displays” section in the Reading Settings page:

    The template then loads when I go to ie. //wordpress.test/blog I even can load patterns in that template, but it seems unable to load blocks that use the query loop. It only shows the page title but not the query block. I don’t understand why wordpress shows the page title, when there are no blocks to show that.

    This is the pattern where I’m loading the query block, with the post template, and query pagination and so… This same pattern works flawlesly while using it with a “Posts page” selected in the “Your hompage displays” section, since then it use home.html template, but then WP says The posts page template cannot be changed.

    <?php
    /**
     * Title: Query (Grid, Inherited)
     * Slug: jeflopo-fury/query--grid-inherited
     * Categories: query
     * Block Types: core/query
     */
    ?>
    <!-- wp:query {"queryId":0,"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"parents":[]},"align":"wide","style":{"spacing":{"blockGap":"var:preset|spacing|100"}} -->
    <div class="wp-block-query alignwide">
        <!-- wp:post-template {"layout":{"type":"grid","columnCount":2}} -->
    <!-- wp:group {"tagName":"article","style":{"spacing":{"padding":{"top":"var:preset|spacing|100","right":"var:preset|spacing|100","bottom":"var:preset|spacing|100","left":"var:preset|spacing|100"},"blockGap":"var:preset|spacing|50"},"border":{"radius":"0.25rem"},"borderColor":"article-border","backgroundColor":"article-base","className":"has-container-shadow","layout":{"type":"default"}},"className":"is-style-container"} -->
    <article class="wp-block-group is-style-container" style="border-radius:0.25rem;padding-top:var(--wp--preset--spacing--100);padding-right:var(--wp--preset--spacing--100);padding-bottom:var(--wp--preset--spacing--100);padding-left:var(--wp--preset--spacing--100)"><!-- wp:post-featured-image {"isLink":true,"aspectRatio":"auto","align":"full"} /-->
    
    <!-- wp:post-title {"isLink":true} /-->
    
    <!-- wp:post-excerpt /-->
    </article>
    <!-- /wp:group -->
    <!-- /wp:post-template -->
    
        <!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"space-between","flexWrap":"wrap"}} -->
        <!-- wp:query-pagination-previous {"label":"Previous"} /-->
        <!-- wp:query-pagination-numbers /-->
        <!-- wp:query-pagination-next {"label":"Next"} /-->
        <!-- /wp:query-pagination -->
    </div>
    <!-- /wp:query -->

    So how could I create and be able to select between multiple templates for the “Posts page” page ?
    I mean, without simply replacing a hardcoded pattern on the home.html template to load my desired “template”.

    Thank you !

    ps: I’m using WP 6.5-alpha-56974 and Only Gutenberg 16.9.0-rc.1

    • This topic was modified 11 months ago by jeflopo.
    • This topic was modified 11 months ago by jeflopo.
    • This topic was modified 11 months ago by jeflopo.
    • This topic was modified 11 months ago by jeflopo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jeflopo

    (@jeflopodev)

    This is how it looks like when I have set the posts page in the reading > settings, but then I can only use the home.html template:

    If I unset the posts page ( — Select — ) I can use whatever custom template I want but then… The query block doesn’t seems to work.

    How can we use different templates for the posts page ?

    Can We *only* do it by replacing the hardcoded pattern we load in the home.html template ?¿?

    <!-- wp:pattern {"slug":"theme-slug/pattern-of-choice"} /-->
    • This reply was modified 11 months ago by jeflopo.
    • This reply was modified 11 months ago by jeflopo.
    • This reply was modified 11 months ago by jeflopo.
    • This reply was modified 11 months ago by jeflopo.
    • This reply was modified 11 months ago by jeflopo.
    Thread Starter jeflopo

    (@jeflopodev)

    I figured out how to do it.
    It’s implemented in TT4.

    Basically, in the editor, in the home template, there’s an action menú to replace the template content.

    I think that the file names must match the slugs of the template hierarchy for wordpress find them.

    • This reply was modified 11 months ago by jeflopo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use the Posts page with multiple templates ?’ is closed to new replies.