• I found a snippet of code that finally takes care of the missing /archive/ page for custom post_types, and in the comments it was mentioned that cms-press takes care of this.

    Is this the case?

    Meaning if I have post type ‘movies’ can I create a theme folder /movies/ with index.php and single.php in there where it will be automatically picked up so long as I refresh my permalinks?

    http://wordpress.org/extend/plugins/cms-press/

Viewing 15 replies - 1 through 15 (of 17 total)
  • Yes, cms-press takes care of this. Instead of using the default permalink handling for custom post_types, cms-press takes the permastructure you setup for the post_type and breaks it down so that the pieces that make up that URL should be browse-able as well. So if your permastructure for a ‘movie’ post_type consisted of example.com/movies/movie-name/, example.com/movies/ would just do a query against post_type=’movie’.

    To theme these pages though, you wouldn’t create a new theme called /movies/. Instead, you would add a single-movie.php to your current theme. So far, 3.0 doesn’t have post_type specific filters for all the page types yet, and I haven’t yet taken care of these in cms-press, so for now, you would need to add a filter to use a custom archive page for movies. I have a ticket setup to fill in the missing template_loads that I will hopefully include in the next release, http://github.com/voceconnect/cms-press/issues/issue/39.

    Thread Starter Anointed

    (@anointed)

    check out http://somadesign.ca/2010/smarter-custom-post-types-in-wordpress-3-0/

    I was reading in the trac about how wp does not yet handle /archive/ pages for custom post_types as of yet, so there is no auto permalink structure created.

    I’m not sure how the rabbit trail went, but somehow I ended up at the link above and it seems to work pretty good.

    Any resolution to this. I have custom post type of projects and cannot get the root of the post type to display with a custom template such as projects.php. Any updates? Fixes?

    Yes, the template handling is built in with the following templates:

    home-{post_type}.php
    index-{post_type}.php
    single-{post_type}.php (how core handles this now)
    {post_type}.php (for cms-press backwards compatibility)
    date-{post_type}.php

    Hmmm. I can’t get any of those templates to work. I even made a fresh installation of WP 3.0, tried again, and still not working.

    Let’s assume I have custom content type ‘cars.’ And I want to create an index to view all ‘cars’ posts at http://www.domain.com/cars/. First, I duplicate my theme’s index.php. (I’m using 3.0’s 2010 theme). Then I rename it ‘index-cars.php’.

    Is that it?

    It’s not working for me. Do I need to modify the loop at all? I’ve also tried adding <?php query_posts('post_type=cars'); ?> to my index-cars.php and still no luck. What am I doing wrong?

    You shouldn’t need the query_posts.

    When you say it doesn’t work. Is it not showing posts of post_type=’cars’ or it just not using the index-cars.php template?

    Got it. I had added Justin Tadlock’s code to my functions.php to make the homepage show all content types. It did. But his code also broke CMS Press’ templating. (I tested it by adding some static text to the index.php, and confirmed that index.php WAS being used for both domain.com and domain.com/cars/ and it ignored completely the index-cars.php template). His code:

    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    	if ( is_home())
    		$query->set( 'post_type', array( 'post', 'cars' ));
    	return $query;
    	}

    So, in short, your plugin is A-Okay. Great, actually! It’s much better than Custom Post Type UI, in my opinion, b/c you allow URL’s to end in .html. CPT UI forces you to end in a trailing slash, which I loathe, and doesn’t fit with my existing permalink structure. So I switched to CMS Press!

    BTW, while we’re talking, do you have a way to display all content types on the homepage and in the main feed?

    To display multiple types, you can use the code you have above, but first check that the post_type isn’t already set.

    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    	if ( $query->is_home && !isset($query->query_vars['post_type']))
    		$query->set( 'post_type', array( 'post', 'cars' ));
    	return $query;
    }

    The reason for this is that currently (I don’t know if this will change in the future), the is_home doesn’t check the post_type of the query. But this is also what allows us to have the home-{post_type}.php

    You rock! I also added || is_feed to get it into the main feed too.

    /** Display all regular posts and specified custom content types on homepage & main feed **/
    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    	if ( $query->is_home || is_feed && !isset($query->query_vars['post_type']))
    		$query->set( 'post_type', array( 'post', 'cars' ));
    	return $query;
    }

    And, I noticed that each content type automatically gets its own feed (feed://www.domain.com/video/feed/) too, either CMS Press or WordPress does it automatically. I’m not sure which, but it’s awesome either way.

    The one and only big thing missing IMO is tag and category support. My dream, and I don’t know if this is even technically possible, would be to have site-wide tags and when on a content type index page, tags filtered by content type. E.x. When a user is on the homepage and they click a tag in a tag cloud, they view any and all content types with the given tag (domain.com/tags/ice-hockey). But if they are on the Video index and they clicked the ‘ice-hockey’ tag, that they’d see only video content tagged ice-hockey (domain.com/video/tags/ice-hockey/). etc. If you could pull that one off (filtering of some type, maybe with templating like you did for content type index pages), then this would be the ULTIMATE plugin IMO.

    (One note I thought might be helpful to you. I noticed in the forums someone really wanted the ability to order panels within the WP admin. It’s actually NOT important to me, like the tags support is. But I wanted to mention that WP Post Type UI (NOT Custom Post Type UI) has a neat dropdown selector for menu position selector that you might be able to integrate in. It’d be a nice interface. And a couple tiny UI things to consider: It’d be nice if the wording was changed to ‘Include in search results’ because the answer ‘yes’ would be parallel with a ‘yes’ on the above option (Is Publicly Queryable?). So people select ‘Yes’ ‘Yes.’ Not ‘Yes’ ‘No’ to have their content widely accessible. Sorry, I only mention that b/c I REALLY like this plugin. Oh, and example text along the way (“e.g. movie, e.g. Movie, e.g. Movies”) might help less experienced ppl along the way when using this the first time.
    Like I said, I really like this plugin and want to see it go blockbuster like All in One SEO…so you keep it going πŸ˜‰ Thanks again!

    oops. That link got messed up. But it still links to a pic of the menu.

    I discovered that my code above to custom content types to the feed as well didn’t work. But after a bunch of guess & check, I adapted your code, prettyboymp, to display all specified content types (e.g. videos, in this case) on the homepage AND in the feed! Add this to functions.php

    /** Display all regular posts and specified custom content types on homepage & in main feed **/
    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    	if ( $query->is_home && !isset($query->query_vars['post_type']) || is_feed && !isset($query->query_vars['post_type']))
    		$query->set( 'post_type', array( 'post','videos' ));
    	return $query;
    }

    Update: This code breaks pages–e.g. /about.html returns ‘Not found.’

    I tried adding an elseif, but it didn’t work. Prettyboymp, do you know to make it not break pages?

    add_filter( 'pre_get_posts', 'my_get_posts' );
    		function my_get_posts( $query ) {
    			if ( $query->is_home && !isset($query->query_vars['post_type']) || is_feed && !isset($query->query_vars['post_type']))
    				$query->set( 'post_type', array( 'post','videos','recipes','recipe' ));
    			elseif ( $query->is_page && !isset($query->query_vars['post_type']))
    				$query->set( 'post_type', array( 'page' ));
    			return $query;
    		}

    Justin Tadlock’s code seems to work. It displays all specified custom content types on the homepage and in the main feed without breaking pages. In case it helps anyone:

    function my_get_posts( $query ) {
    			if ( ( is_home() && false == $query->query_vars['suppress_filters'] ) || is_feed() )
    			$query->set( 'post_type', array( 'post', 'videos', 'attachment' ) );
    			return $query;
    			}
    		add_filter( 'pre_get_posts', 'my_get_posts' );

    It looks like you were missing some parentheses in that first if statement after you added the || is_feed().

    Thanks. I’m not a coder. But I copy and paste and try, try, try. πŸ˜‰

    Any update on when tags and category support might be ready in CMS Press?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘does cms-press take care of the post_type archive permalinks?’ is closed to new replies.