WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type Slug vs Page Slug (4 posts)

  1. alexray
    Member
    Posted 2 years ago #

    Hello,

    This is my first post here on the WordPress forums. Luckily I have been able to get by using the codex and forum search. I am just learning wordpress as I create themes and troubleshoot them along the way.

    Anyway,

    I have recently started dabbling in custom post types.
    I have a custom post type called "Portfolio"
    Currently each post displays perfectly with the permalink structure as
    site.com/portfolio/%post-name%

    I also have a page that displays my portfolio entries (which I did by creating a page and applying the page-portfolio.php template to it)
    Currently it is set at
    site.com/portfolio-home/

    What I want is my portfolio page to show up as
    site.com/portfolio/
    and each entry to go to
    site.com/portfolio/%post-name%

    If i do this now, it creates problems and my page-portfolio.php template doesnt show up. I am thinking it has to do with slugs and rewrites which is why I changed it to portfolio-home to get around it. However, I don't like the way that looks.

    Any ideas?

    if it helps, I used this tutorial to create my custom post type:
    http://wp.tutsplus.com/tutorials/creating-a-filterable-portfolio-with-wordpress-and-jquery/

    Thanks in advance.

  2. stvwlf
    Member
    Posted 2 years ago #

    You can't really do what you are trying to do in the way you would like to do it.

    /portfolio/ is registered with the custom post type as the custom post type permalink associated with that custom post type.

    when you give a page the same permalink that is associated with the custom post type permalink, you create a conflict. WordPress knows how to display pages based on the requested URL and what are called the rewrite rules. This is a sequential list of all the possible rules of URL's that your site can display. It goes down the list one by one looking for a rule that matches. Custom Post Type rules are ahead of page rules in the sequence. So when WordPress sees
    site.com/portfolio/
    it knows that as the custom post type archive page, and that is what its going to display. It doesn't even reach the part of its rules that are aware of site.com/portfolio/ as a page because it has already taken action on the first match it found, which is the custom post type archive page.
    You have a URL clash - two types of content trying to display at the same URL. That won't work.

  3. alexray
    Member
    Posted 2 years ago #

    Gotcha.

    Well it was worth a shot checking the forums. Thanks for the input on the subject. I really appreciate it.

  4. tkamin
    Member
    Posted 1 year ago #

    Hi,

    I solved this conflict by adding an "archive-<post_type>.php" template, grabbing the page directly and starting a new loop. In this case, here would be the contents of "archive-portfolio.php"

    query_posts( 'post_type=page&name=portfolio' );
    // The Loop
    if ( have_posts() ) : the_post();
    include( 'template-portfolio.php' );
    endif;

Topic Closed

This topic has been closed to new replies.

About this Topic