Forums

How can i check for post_types in the templates? (2 posts)

  1. expat
    Member
    Posted 6 months ago #

    How can i check for post_types in the templates?

    1. post
    2. page
    3. event post_types?

    cheers

  2. Big Bagel
    Member
    Posted 6 months ago #

    To check if it's a page:

    Function Reference/is page

    To check if it's a single post:

    Function Reference/is single

    To check for a custom post type, it can depend on when and where you want to check. For example, if your in the loop, you could do something like this:

    if ( 'my_post_type' == get_post_type() ) {
        /* Stuffs */
    } else {
        /* Other stuffs */
    }

    Function Reference/get post type

    You can also make specific single and archive template files that target a specific post type. You check out this page for more information on that:

    Template Hierarchy

Reply

You must log in to post.

About this Topic