Created
March 22, 2013 16:32
-
-
Save TheHeat/5222729 to your computer and use it in GitHub Desktop.
In WordPress display the title and content of an hierarchical post-type with h tags based on the level of the hierarchy. Top level posts have <h1> titles, their children <h2> and so on. I used this to create a Terms and Conditions page based on a hierarchical custom-post-type. I've also included the post slug as the section ID for better navigat…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $args = array( | |
'sort_order' => 'ASC', | |
'sort_column' => 'menu_order', | |
'hierarchical' => true, | |
'post_type' => 'post_type', | |
'post_status' => 'publish' | |
); | |
$post_type = get_pages($args); | |
foreach ($post_type as $post_object): | |
$title = $post_object->post_title; | |
$slug = $post_object->post_name; | |
$content = $post_object->post_content; | |
$hlevel = count(get_post_ancestors($post_object->ID))+1; | |
?> | |
<section id="<?php echo $slug; ?>" class="<?php hybrid_entry_class(); ?>"> | |
<?php echo "<h" . $hlevel . ">"; echo $title; echo "</h" . $hlevel . ">"; ?> | |
<?php echo apply_filters( 'the_content', $content); ?> | |
</section> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment