Forums

[resolved] How could I find template name used by a Page ? (2 posts)

  1. svart
    Member
    Posted 1 year ago #

    Hi,

    I want to do this :

    - On a page, I list every subpages of this page
    - For each subpage, I want to know the template used by this subpage
    - So i could choose the right icon for the right template

    The problem is i'm doing it outside the loop.

    get_pages brings me alot, but no the template name used.

    I checked the database but wasn't able to find out where the template name for a post with a post_type of "page" is stored.

    Any idea how to have a function, with a ID, that could retrieve the template name of that ID ?

  2. svart
    Member
    Posted 1 year ago #

    Ok, I finally find it by looking at the wp-includes/post-template.php

    The value is stored in the meta-data of the post. It is logical.

    We can retrieve it by the get_post_meta() function.

    The code I use is so :

    $PageTemplateName = get_post_meta($SubPage->ID, '_wp_page_template', true);

    The last part (, true) is there to retrieve a value instead of an array.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.