WordPress.org

Ready to get started?Download WordPress

Forums

does cms-press take care of the post_type archive permalinks? (18 posts)

  1. Anointed
    Member
    Posted 4 years ago #

    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/

  2. prettyboymp
    Member
    Posted 4 years ago #

    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.

  3. Anointed
    Member
    Posted 4 years ago #

    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.

  4. KompaniGroup
    Member
    Posted 4 years ago #

    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?

  5. prettyboymp
    Member
    Posted 4 years ago #

    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

  6. AlexLakes
    Member
    Posted 4 years ago #

    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?

  7. prettyboymp
    Member
    Posted 4 years ago #

    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?

  8. AlexLakes
    Member
    Posted 4 years ago #

    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?

  9. prettyboymp
    Member
    Posted 4 years ago #

    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

  10. AlexLakes
    Member
    Posted 4 years ago #

    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!

  11. AlexLakes
    Member
    Posted 4 years ago #

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

  12. AlexLakes
    Member
    Posted 4 years ago #

    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;
    }
  13. AlexLakes
    Member
    Posted 3 years ago #

    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;
    		}
  14. AlexLakes
    Member
    Posted 3 years ago #

    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' );
  15. prettyboymp
    Member
    Posted 3 years ago #

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

  16. AlexLakes
    Member
    Posted 3 years ago #

    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?

  17. mongushu
    Member
    Posted 3 years ago #

    Hey All,

    I'm stuck exactly here (as described by AlexLakes):

    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?

    For me, all the proper content displays as it should @ the URLs according to CMSPress per content_type URL setting, but wordpress seems to completely ignore the templating rules. In other words, 'index.php' is being used, and all other template files [named in accordance with WP 3 custom post type templating hierarchy] are ignored. index-my_post_type.php does not work. archive-my_post_type.php does not work either.

    any ideas?

    WP 3.0.4
    CMSPress 0.2.0

  18. mongushu
    Member
    Posted 3 years ago #

    more....

    for example, lets consider a custom post type of "car".

    First, I've edited my index.php file and have added:

    if( get_post_type() == 'car' ){
    echo 'car';
    }

    I go to: http://mysite.com/car/

    and

    car

    is echoed out.

    However when replace that snippet with this:

    if( is_archive() ){
    echo 'archive';
    }

    and then I go to http://mysite.com/car/

    nothing is echoed out.

    In other words, WordPress does not seem to think that http://mysite.com/car/ is an archive. And I bet this is why it's not going and retrieving the proper template file.

    Any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags