Menu

Display pages by category

February 1, 2014 - wordpress

code:

 

<?php
//get all terms (e.g. categories or post tags), then display all posts in each term
$taxonomy = ‘topics’;// e.g. post_tag, category
$param_type = ‘topics’; // e.g. tag__in, category__in
$exclude=array(“home”, “uncategorized”);
$term_args=array(
‘orderby’ => ‘name’,
‘order’ => ‘ASC’
);
$terms = get_terms($taxonomy,$term_args);
//echo count($terms);
if ($terms) {
foreach( $terms as $term ) {
if(!in_array($term->slug , $exclude))
{
$args = array(
‘post_type’ => array(‘page’),
‘post_status’ => ‘publish’,
“$param_type” => $term->slug
);

$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo ‘List of Posts in ‘.$taxonomy .’ ‘.$term->name;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></p>
<?php
endwhile;
}
}
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>

Leave a Reply