Last active
January 16, 2018 07:44
-
-
Save viramgamijignesh/84818cdb135f472afea5a142bb76df73 to your computer and use it in GitHub Desktop.
Category wise post display
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 | |
/* Template Name: Category Post Template */ | |
get_header(); | |
?> | |
<div id="container"> | |
<div id="content" role="main"> | |
<?php | |
// get all the categories from the database | |
$cats = get_categories(); | |
// loop through the categries | |
foreach ($cats as $cat) { | |
// setup the cateogory ID | |
$cat_id= $cat->term_id; | |
// Make a header for the cateogry | |
echo "<h2 style='text-align:center'>".$cat->name."</h2>"; | |
// create a custom wordpress query | |
query_posts("cat=$cat_id&posts_per_page=100"); | |
// start the wordpress loop! | |
if (have_posts()) : while (have_posts()) : the_post(); ?> | |
<?php // create our link now that the post is setup ?> | |
<div class="container"> | |
<div id="primary" class="content-area"> | |
<main id="main" class="site-main" role="main"> | |
<div class="entry-content" style="width:90%; text-align: center;float: none;"> | |
<a href="<?php the_permalink();?>"><?php the_title(); ?></a> | |
</div><!-- #post-## --> | |
</main><!-- #main --> | |
</div><!-- #primary --> | |
</div><!-- .wrap --> | |
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?> | |
<?php } // done the foreach statement ?> | |
</div><!-- #content --> | |
</div><!-- #container --> | |
<?php get_sidebar(); ?> | |
<?php get_footer();?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment