WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP3.1 : custom post types templates (5 posts)

  1. grosbouff
    Member
    Posted 3 years ago #

    Hi, i've read there will be a new feature to have specific templates for custom post types; but I wasn't able to find good explanations.
    in my code, i have

    register_post_type( 'yclad'
    ...
    'rewrite' => Array( 'slug' => _x('classified-ads','slug','yclads'), 'with_front' => false ),
    'has_archive' => true

    So If I well understood, with this;

    1. /classified-ads/ will be the rewritten url for this post type.
    2. archive-yclad.php should be the template loaded when accessing /wordpress/?post_type=yclad

    Is that correct ?

    BTW,
    /classified-ads/my-post works; but
    /classified-ads/ goes to 404.

    I did try to refresh the permalinks, and also to put

    flush_rewrite_rules( false );

    just after

    register_post_type(...

    It does not work.

    Also, is there a conditionnal tag to check if we are browsing a particular post type ?
    I would like a function to detect if we are on /wordpress/?post_type=yclad

    Is there something like is_archive('yclad') ?

  2. grosbouff
    Member
    Posted 3 years ago #

    Also, what is weird with all this; is that
    wordpress/?post_type=yclad

    will try to load archive-yclad.php

    but that when you try

    is_archive() in your function.php, it returns false.

  3. Sergey Biryukov
    Trac Moderator
    Posted 3 years ago #

    Also, is there a conditionnal tag to check if we are browsing a particular post type ?

    http://codex.wordpress.org/Conditional_Tags#A_Post_Type

  4. grosbouff
    Member
    Posted 3 years ago #

    Not really a conditional tag, but returns the registered post type of the current post.

    -->so it's not a conditional tag for the query...

  5. Sergey Biryukov
    Trac Moderator
    Posted 3 years ago #

    Ah, right. There's also is_post_type_archive():
    http://codex.wordpress.org/Function_Reference/is_post_type_archive

Topic Closed

This topic has been closed to new replies.

About this Topic