Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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' ).

share|improve this answer
    
To clarify: a) I want to be able to create "My Stuff" blog posts, which use a custom "My Stuff" write panel. This is not the diffcult part. b) I want to be able to link to the "My Stuff" category, taxonomy or whatever we're calling it. c) I don't want "My Stuff" posts to appear in the main blog. –  user5486 May 22 '11 at 9:41
    
@user5486 c) Doesn’t happen already. This post type works now like a sub blog. · · But I still don’t understand how the Stuff Post Type should act as a taxonomy. Only Custom Post Types have an editor etc. –  toscho May 22 '11 at 11:30
    
I'm using the taxonomy term because I want "My Stuff" to be linkable. If it can be linked as a page, as Chris suggests, then fine, we don't need a taxonomy. I'm attempting to create blog posts (created from a custom write panel) that appear where I want them but NOT on the main blog. –  user5486 May 22 '11 at 19:02
    
@user5486 The custom post types from my example will not appear on your regular blog pages, just at example.com/stuff/. You can list these posts on other places too, of course. get_posts() or WP_Query will help. –  toscho May 22 '11 at 19:19

I just had to do something similar. My solution was to create a template php file and then create a Page that used the template. In the template was a WP_Query to create the loop.

At the top of the template file:

<?php /* Template Name: <template name> */ ?>

and in the template file:

$args=array('post_type' => 'my_stuff', 'posts_per_page' => 10);
$loop = new WP_Query( $args );
while ($loop->have_posts()) : $loop->the_post();

Then I created a Page and in the attributes I selected the template name from the list.

share|improve this answer
    
Thanks, Chris. You appear to be suggesting that you're able to create blog posts and display them in a series through a page template. I'll give it a try. However, I'm not quite sure what to do with your wp_query snippet. Can you provide it as a closed php statement? –  user5486 May 22 '11 at 9:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.