ThemeShaper Forums » Thematic


How to add a custom post-type on my child theme

(7 posts)
  • Started 8 years ago by WebInk
  • Latest reply from WebInk
  • This topic is resolved
  1. I'm trying to create a custom post type that is named 'Books'. I'm currently using this child theme and I'm kinda lost in adding the custom type. Below is what I putted in my functions.php. What's missing in my code and how am i able to make custom loop for my 'Books'

    /* New Post-Type */

    add_action( 'init', 'create_post_type' );

    function create_post_type() {
    register_post_type( 'Books',
    'labels' => array(
    'name' => __( 'Books' ),
    'singular_name' => __( 'Book' ),
    'add_new' => __( 'Add New Book' ),
    'edit' => __( 'Edit' ),
    'search_items' => __( 'Search Book' ),
    'not_found' => __( 'No Books Found' ),
    'parent' => __( 'All Books' ),
    'public' => true,
    'menu_position' => 5,
    'has_archive' => true,
    'rewrite' => array('slug' => 'books'),
    'can_export' => true,
    'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' ),
    'taxonomies' => array('post-tag', 'category', 'categories'),


    Posted 8 years ago #
  2. post types in child themes are exactly the same as in regular themes. at first glance you are missing register_post_type(). please take a look at google and the wordpress codex. there are literally a gazillion tutorials on exactly this already.

    justin tadlock has a a great tutorial that appears on the first page of google.

    as does the codex result (which also has sample code)

    Posted 8 years ago #
  3. Hi helgatheviking, thank you for your response. Actually the link you posted was my reference when i was building my code. The register_post_type() is in the 6th line above. below "function create_post_type() {".

    I was able to successfully build the form in the backend. I also think my question is wrong... Sorry for that...

    So i successfully created the custom post type. let say it's called "Books"

    I wanted to have a link in my main menu where I can have a loop fetching all "Books". Below is how my navigation is structured.

    Navigation Structure::
    - Home [Page]
    - Products [Page]
    - Books [Custom Post-Type]
    - Services [Page]
    - Contact [Page]
    - Blog [Post]

    I'm not sure how I would create that in my functions. Are you familiar with what i'm trying to do?


    Posted 8 years ago #
  4. custom post type archives have been supported since WP3.1

    even w/o a custom template they should still be displayed by the default archive template, so if you visit you should see something.

    if the problem is adding it to the menu well i don't believe you can add CPT archives to the menu yet, which is crap but there ya go. even though 'show_in_nav_menus' is set to the value of 'public' by default... so in your case true, that only seems to allow you to add just single items. best bet for the moment is a custom link.

    Posted 8 years ago #
  5. Hi Helga, thank you for your response I didn't even try to access the url (/books). This solve the issue, I will just point my menu into that url. Problem solve. thanks!

    Posted 8 years ago #
  6. everyone facepalms now and then.

    Posted 8 years ago #
  7. yes. true! lolz

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.