functions.php
/* custom post type trove */ function trove_custom_init() { $labels = array( 'name' => __('Treasure Trove','themename'), 'singular_name' => __('trove','themename'), 'add_new' => __('Add New','themename'), 'add_new_item' => __('Add New Treasure Trove','themename'), 'edit_item' => __('Edit Treasure Trove','themename'), 'new_item' => __('New Treasure Trove','themename'), 'all_items' => __('All Treasure Trove','themename'), 'view_item' => __('View Treasure Trove','themename'), 'search_items' => __('Search Treasure Trove','themename'), 'not_found' => __('No Treasure Trove found','themename'), 'not_found_in_trash' => __('No Treasure Trove found in Trash','themename'), 'parent_item_colon' => "", 'menu_name' => __('Treasure Trove','themename') ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'trove' ), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => true, 'menu_position' => null, 'supports' => array( 'title', 'editor','thumbnail','page-attributes'), ); register_post_type( 'trove', $args ); } add_action( 'init', 'trove_custom_init' );
Display Posts
<div class="blog-details single"> <?php global $post; $troveargs = array( 'paged' => $paged, 'post_type' => 'trove', 'post_status' => 'publish', 'order' => 'ASC', 'post_parent' => 0 ); $trove_query = new WP_Query($troveargs); while ( $trove_query->have_posts() ) : $trove_query->the_post(); //if ($post->post_parent == 0) { ?> <div class="col-md-12 no-padding trovebox"> <h2> <?php the_title(); ?> </h2> <p> <?php the_content(); ?> </p> </div> <?php /* Start Second Loop of sub procuct listed under main product */ $troveargs_sub = array( 'paged' => $paged, 'post_type' => 'trove', 'post_status' => 'publish', 'order' => 'ASC', 'post_parent' => $post->ID ); $trove_query_sub = new WP_Query($troveargs_sub); while ( $trove_query_sub->have_posts() ) : $trove_query_sub->the_post(); //echo wp_get_post_parent_id( $post_ID ); ?> <div class="col-md-12 no-padding trovebox"> <h4> <?php the_title(); ?> </h4> </div> <?php endwhile; /* End Second Loop*/ ?> <?php endwhile; ?> </div>
Tagged: custom_post_type, display, loop, page attribute
Leave a comment