Skip to content

Instantly share code, notes, and snippets.

@manishsongirkar
Created October 18, 2012 11:01
Show Gist options
  • Save manishsongirkar/3911036 to your computer and use it in GitHub Desktop.
Save manishsongirkar/3911036 to your computer and use it in GitHub Desktop.
Add Wordpress Category list in pages as shown in posts
function create_page_taxonomy() {
register_taxonomy( 'category', array( 'page', 'post' ), array(
'hierarchical' => true,
'label' => __( 'Categories' ),
'singular_label' => __( 'Category' ),
'show_ui' => true,
'query_var' => true,
'rewrite' => true
) );
}
add_action( 'init', 'create_page_taxonomy' );
$the_query = new WP_Query( array(
'post_type' => 'page',
'category_name'=> 'catname'
) );
echo '<ul class="custom-class">';
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li>';
echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a>';
echo '</li>';
endwhile;
echo '</ul>';
// Reset Post Data
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment