Forums

[resolved] Custom Post Types 'single-type.php' not working (8 posts)

  1. Melee VIII
    Member
    Posted 1 year ago #

    For my website I want to make use of the Custom Post Types functions and give these custom posts a different look. I made the custom post type with the following code in my functions.php:

    add_action('init', 'digest_register');
    
    	function digest_register() {
        	$args = array(
            	'label' => __('digest'),
            	'singular_label' => __('digest'),
            	'public' => true,
            	'show_ui' => true,
            	'capability_type' => 'post',
            	'hierarchical' => false,
            	'rewrite' => array( 'slug' => 'digest', 'with_front' => false ),
            	'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'thumbnail')
            );
    
        	register_post_type( 'digest' , $args );
    	}

    I have made a 'single-digest.php' but when I go to a post's URL I see the homepage.

    Anyone that can tell me what I should do to make the single post page work?

  2. wishypw
    Member
    Posted 1 year ago #

    i'm also having this problem. but slightly different;

    As well as the single-customposttype.php files, I also have a single.php in my theme directory which as a routing rule for the different post types to point to a different single file.

    Strangely, one single works yet the other doesn't any ideas?

  3. benzine
    Member
    Posted 1 year ago #

    You should duplicate the page.php and give it the name page-yourpost.php and add this line of code on top for WP to recognize it as a template file

    * Template Name: your post name Template

    add this before the loop

    <?php query_posts(array('post_type'=>'your post')); ?>

    You'll have the custom post type being created in your admin. Create a page and then assign the page to page-yourpost.php from the drop down list under Page attributes and you're done

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    or wait for WP 3.1

    when you can just use archive-post_type.php, and turn archives on in your CPT, and be done with it! No custom queries

    http://mark.mcwilliams.me/2010/10/wordpress-3-1-introduces-custom-post-type-archives/

    (@ benzine, you need to include pagination in your query... http://www.rvoodoo.com/projects/wordpress/wordpress-tip-fixing-pagination-on-custom-queries-with-query_posts/ )

  5. wishypw
    Member
    Posted 1 year ago #

    thanks guys, i'll give your suggestions a go and let you know!

  6. benzine
    Member
    Posted 1 year ago #

    @ Rev. Voodoo

    Can you pls help me on this issue

    http://wordpress.org/support/topic/one-and-two-columns-posts-on-the-same-page?replies=7#post-1849587

    I'm stuck here!!!

    Waiting for your feedback

    Thanks
    Ben

  7. justtj
    Member
    Posted 10 months ago #

    I had similar issue, and spent few hours trying to figure out why.

    In end realized that when we add a custom post type, the .htaccess file doesn't update the permalink structure.

    So just update the permalink structure {switch to something else and back again} and everything will work fine.

    cheers!

  8. Blizzie
    Member
    Posted 8 months ago #

    I have the same issue. I want custom post type to have different template when viewed individually. I am using magazine-basic as my theme and all codes for single.php and etc. are in the loop.php Can't seem to figure how to tweak it. Please help. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic