Forums

[resolved] Fully use template tags in Custom Page Template (5 posts)

  1. nemo.vrusso
    Member
    Posted 3 years ago #

    Hello everybody,

    I was wondering if there is a way to use some template tags in a custom page template.

    Let 'P' be a page. Let us assume that we use a custom page template 'T' with this page. It would be very useful to use the content of the page 'P' within the template 'T', in a straightforward way.

    For example, within a template I can use "the_title" to get the title of the page the template is attached to. But not the other template tags (the_ID, the_content, etc.). I think it should be allowed.

    Is it possible in some not straightforward way? Meanwhile I "cheated" by using get_post($id_of_the_page_with_custom_template_attached). By I think that if "the_title" is available, the other template tags too could be.

    Should I open a feature request ticket somewhere?

  2. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    Are you using a loop? You can use all of the tags you listed inside The Loop.

  3. nemo.vrusso
    Member
    Posted 3 years ago #

    No Loops here.

    Imagine you want to replicate the behavior of page.php in the template 'T'. Usually in the single.php and page.php you can use all the template tags like "the_title, the_content, the_ID" etc. which return their results in relation to the current page/post displayed.

    Currently in a custom page template you can use only "the_title" to get the title of the page which the template is attached to. But not the other tags (of course you can use all the tags in a Loop, but it is not what I want to do).

    If the behavior I am trying to explain here would be available, you could use the fields of a page to store some stuff that you can then use in the template attached to that page.

    Concrete example: I am building a website for a company. In this website there is a page "Partners".

    The structure of that page has to be:

    - Title
    - Some text to explain the page content
    - A list of partners

    This is what I did:

    - I created a link category "Partners"
    - I added partners' information as "Links" (Blogroll) under the above category
    - Created a wordpress page "Partners"
    - Created a wordpress custom page template "Partners template"
    - In the template I use 'get_bookmars()' to get the partners' information
    - In the template I use "the_title()" to get the title of the page which the template is attached (that is, "Partners" in this case)

    If you look at the structure explained above, the problem is that at this point I can retrieve the title and the list of partners from the DB, but not the "some text".
    I stored that text in the "content" of the "Partners" page, but I cannot retrieve it in the same straightforward way I retrieved the title, i.e. the_content() returns nothing.

    What I was wondering is "why allow the_title and not the other tags?" It would be very useful. At least to me. But I think that other people should find this very useful.

  4. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    see my prior post -> use a loop!!

  5. nemo.vrusso
    Member
    Posted 3 years ago #

    Ok, my fault. I was drunk! :D

Topic Closed

This topic has been closed to new replies.

About this Topic