Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: [Assigned] Bottom Level Posts Listed Inside Related Top Level Posts – Possible?

$
0
0

Dear dmfzw,

My apologies for the delay. I got it how to make this using custom post types. This link was much useful I would say. Open your functions.php file and then place the code below within:

add_shortcode( 'getchildposts', 'getchildposts_func');
function getchildposts_func($atts){
	extract( shortcode_atts( array(
	'type' => '',
	), $atts ) );
		?>	
		    <?php
		    query_posts('&post_type='.$type.'&post_parent=0');?>
		    <ul>
		    <?php while(have_posts()):the_post(); ?>
		    		<li>
		    			<?php the_title(); ?>
		    			<?php		    	
		    				$pageChildren = get_pages('child_of='.get_the_ID());		    			
		    			?>
		    			<?php
		    			if ( $pageChildren ) {
		    				echo('<ul>');
						  foreach ( $pageChildren as $pageChild ) {
						  	echo('<li>'.$pageChild->post_title.'</li>');
						  }
						  	echo('</ul>');
						}
						?>
		    		</li>
		    <?php endwhile;?>
			</ul>
		    <?php wp_reset_query(); ?>
		<?php
}

This code will create a custom shortcode and it needs be used like this [getchildposts type="page"] where page is your custom post type, you can use for any CPT.

Hope it help you.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.


Viewing all articles
Browse latest Browse all 20145

Trending Articles