• Hi Guys,
    So take
    <?php get_template_part( 'loop-templates/content', 'page' ); ?>
    …how do I adjust this so that when I visit a page with a slug say about-us that the code pull the template file loop-templates/content-about-us.php if it exists if not default to content-page.
    I’d like to pull a template part based of a dynamic page or category using a slug system.
    New to WP so trying to figure the logic.
    Thanks

Viewing 1 replies (of 1 total)
  • The way that teh templating would work is for you to get a variable from somewhere to tell you what page you want to show, and that would work like this:

    get_template_part ('loot-template/content', $your_page);

    Then just set up the template files like this:

    loop-template/content.php
    loop-template/content-page.php

    That’s assuming that you’re $your_page variable will be ‘page’.

    What will happen is that WordPress will look for content-page.php and if that’s not found, default back to content.php instead. That way you can set up as many template files as you need to suit your system, and always have the default for any that don’t match.

Viewing 1 replies (of 1 total)

The topic ‘template parts calling dynamic page’ is closed to new replies.