Show All Categories and Post Topics only (PHP)

Purpose: Show All WordPress Blog Categories and the Post topic names only

A WordPress PHP script. An example of the action can be seen in the Archives page of this blog. It is a tidy view with no other fusshuss to easly navigate through the stuff written in here. More old fashioned hierarchical way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
        <?php
        $categories=get_categories($args);
        foreach($categories as $category) { 
            echo '<p><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ('. $category->count .')</p> ';
 
            //display posts
            $cat_new = $category->term_id;
            $post_args = array( 'numberposts' => 5, 'category' => $cat_new, 'caller_get_posts' => 0 );
 
            echo('<ul>');
 
            $myposts = get_posts( $post_args );
            foreach( $myposts as $post ) { 
            ?>
 
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
 
            <?php
            }
            echo('</ul>');
        }
 
        ?>
		<?php
	   	$categories=get_categories($args);
   		foreach($categories as $category) { 
			echo '<p><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ('. $category->count .')</p> ';

			//display posts
			$cat_new = $category->term_id;
			$post_args = array( 'numberposts' => 5, 'category' => $cat_new, 'caller_get_posts' => 0 );

			echo('<ul>');

			$myposts = get_posts( $post_args );
			foreach( $myposts as $post ) { 
			?>

			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

			<?php
			}
			echo('</ul>');
		}

		?>

Leave a Reply

Your email address will not be published. Required fields are marked *


+ eight = ten

Post Navigation