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.

I am currently working on creating an events section for a website. My original plan was to create a custom post type for Events and create a new post for each event. Then I would query the top five events on the home page. My problem is that I need to have sub pages/posts for each event. These pages/posts will need to show up in a sidebar when the single event post is viewed. Is that possible?

Can I create a parent/child relationship with each event post and its sub posts or would it be better to use custom taxonomies to organize this information? The site will be client updated, so I need to create a system that is straightforward and sustainable with a logical permalink structure.

Any help would be greatly appreciated. Thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

when you create a custom post type, and make it hierarchical, it will behave like pages. so you can have sub events the same way you have sub pages.

look at register_post_type function arguments here : http://codex.wordpress.org/Function_Reference/register_post_type#Arguments

then use wp_list_pages function to list subpages. see : http://codex.wordpress.org/Function_Reference/wp_list_pages#List_members_of_a_custom_post_type

something like this (not tested) :

<?php
$args = array(
  'title_li'  => '',
  'child_of'  => $post->ID,
  'post_type' => 'event',
  'title_li'  => __('Sub events'),
  'echo'      => 0,
)
$children = wp_list_pages( $args );
if ( $children ) {
?>
  <ul>
    <?php echo $children ?>
  </ul>
<?php } ?>

please, see this topic on the WordPress forum also.

all you need seems to be in the codex. do not hesitate to follow its rules. here you will find nearly all the tools you wish : http://codex.wordpress.org/Function_Reference/

seb.

share|improve this answer
    
Thanks! That helps a lot. –  Susan Dec 23 '11 at 15:55
    
I have created a hierarchical custom post type called Events and it is working great. I am now able to list sub-posts for each event in a sidebar using wp_list_pages as you suggested. My only problem is that I cannot figure out how to highlight the current post in the menu. I am used to using .current_page_item, but this does not seem to apply to custom posts. Any suggestions would be appreciated! –  Susan Jan 2 '12 at 14:58
    
sorry, i recieved no warning for your next question... it seems that you are right. the current_page_item is not displayed :( i've modified the code a bit so you may try this instead : <?php $args = array( 'child_of' => array_pop( get_post_ancestors( $post->ID ) ), 'post_type' => 'event', 'title_li' => __('Sub events'), 'echo' => 0, ); $children = preg_replace( '/page-item-' . $post->ID . '/', 'current_page_item page-item-' . $post->ID, wp_list_pages( $args ) ); if ( $children ) { ?> <ul> <?php echo $children ?> </ul> <?php } ?> –  Sébastien Méric Jan 9 '12 at 18:35
    
arg ! this is ugly ! i've made 2 changes : replace $children = wp_list_pages( $args ); with $children = preg_replace( '/page-item-' . $post->ID . '/', 'current_page_item page-item-' . $post->ID, wp_list_pages( $args ) ); –  Sébastien Méric Jan 9 '12 at 18:43
    
and 'child_of' => $post->ID, with 'child_of' => array_pop( get_post_ancestors( $post->ID ) ), so the menu will work in your sub events showing the top level ancestors with all childs. –  Sébastien Méric Jan 9 '12 at 18:46
show 1 more comment

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.