Here’s what I’d like to do:
a) Create a custom post type and write panel for a menu item called “My Stuff.”
b) “My Stuff” will behave like a category — but the content will not appear in the main blog. It will only appear under “My Stuff.”
So, what do I need to do? Create another loop? If so, where would I put the second loop, and how would I create a link to “My Stuff”?
Or should I add “My Stuff” to the loop in index.php, create a “My Stuff” category (or taxonomy) and filter “My Stuff” somehow so it only displays when certain fields are present?
Apologies for the complicated question, but I find this all very confusing. None of the scattered tutorials available on the topic clearly explain how to display custom post type content anywhere other than on a page or through the loop.
I’d appreciate any assistance.
Thanks.
a) Create a custom post type and write panel for a menu item called “My Stuff.”
Simple. The Codex should tell you everything you need to know.
But here is another example:
add_action( 'init', 'wpse_17863' );
/**
* Creates a visible post type.
*
* Don’t forget to visit wp-admin/options-permalink.php once to refresh
* the rewrite rules!
*
* @return void
*/
function wpse_17863()
{
$labels = array (
// Usually plural.
'name' => 'Stuffies'
, 'singular_name' => 'Stuffy'
, 'add_new' => 'New Stuff'
, 'add_new_item' => 'Add New Stuff'
, 'edit_item' => 'Edit Stuffy'
, 'new_item' => 'New Stuffy'
, 'view_item' => 'View Stuffy'
, 'search_items' => 'Search Stuffies'
, 'not_found' => 'No Stuffies found'
, 'not_found_in_trash' => 'No Stuffies found in Trash'
, 'parent_item_colon' => 'Parent Stuffy:'
);
register_post_type(
'stuffy'
, array (
// visible
'public' => TRUE
// Menu main name, usually plural
, 'label' => 'Stuffies'
// All labels
, 'labels' => $labels
// Menu position
// 5 - below Posts
// 10 - below Media
// 15 - below Links
// 20 - below Pages
// 25 - below comments
// 60 - below first separator
// 65 - below Plugins
// 70 - below Users
// 75 - below Tools
// 80 - below Settings
// 100 - below second separator
, 'menu_position' => 5
// permalinks
, 'rewrite' => array ( 'slug' => 'stuff' )
// Create a default archive at /stuff/
, 'has_archive' => TRUE
// Allow child pages.
, 'hierarchical' => TRUE
// Add it to custom menus
, 'show_in_nav_menus' => TRUE
// Components of the editor.
, 'supports' => array (
'editor'
, 'excerpt'
, 'page-attributes'
, 'thumbnail'
, 'title'
)
// We use the built-in taxonomies too.
, 'taxonomies' => array ( 'category', 'post_tag' )
)
);
}
b) “My Stuff” will behave like a category — but the content will not appear in the main blog. It will only appear under “My Stuff.”
I don’t understand this part. A custom post type may use a taxonomy – I added categories and tags in my example for a demonstration – but it isn’t one. You can use parent-child relationships tough like with pages.
I you clarify this point in your question I may be able to update my answer.
None of the scattered tutorials available on the topic clearly explain how to display custom post type content anywhere other than on a page or through the loop.
The parameter 'has_archive'
is rather new. Older tutorials may not mention it.
To link to your new archives in themes or plugins use get_post_type_archive_link( 'stuffy' )
.