different template for first and second level custom post page

i needed something similar and i’ve come up with this simple little function that make things easier : function is_child_post($parent_ID = null) { global $post; if (isset($parent_ID) && $parent_ID != null){ return $post->post_parent == $parent_ID; } return $post->post_parent > 0; } Usage: check if a post/page/custom has a parent: if (is_child_post()){ //yes we have a … Read more

Need post_type_archive_title function but in ‘single’

There doesn’t appear to be one, but the following should work: //Get post type $post_type_obj = get_post_type_object( get_post_type() ); //Get post type’s label $title = apply_filters(‘post_type_archive_title’, $post_type_obj->labels->name ); $archive_title = apply_filters(‘post_type_archive_title’, $post_type_obj->labels->all_items); This can, for instance, be put in one generic header template that is applied to all single-cpt files. With is_single() it can be … Read more

Loop through posts of a custom-post-type (event) and create .ics (iCal) file?

This is entirely based on Event Organiser (a plug-in I’ve developed). The code is lifted almost straight from the source but with alterations. As such I’ve not tested the code as given. Step 1: Create a feed This is simple: add_action(‘init’,’wpse63611_add_events_feed’); function wpse63611_add_events_feed(){ add_feed(‘my-events’,’wpse63611_events_feed_output’); } This adds a feed to your site: www.site.com?feed=my-events or www.site.com/feed/my-events … Read more

If post_type is This or This

Use a switch statement and combine your matching cases. function set_custom_post_types_admin_order( $query ) { // If not admin or main query, bail. if( !is_admin() || !$query->is_main_query() ) return; $post_type = $query->query[‘post_type’]; switch( $post_type ) { case ‘games’: case ‘consoles’: //case ‘other_example_match’: $query->set(‘orderby’, ‘title’); $query->set(‘order’, ‘ASC’); break; default: return; } } add_action( ‘pre_get_posts’, ‘set_custom_post_types_admin_order’ ); Hope … Read more