Skip to content

Instantly share code, notes, and snippets.

@EastSideCode
Created May 3, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EastSideCode/25d20f2465d4b723665d64188d887617 to your computer and use it in GitHub Desktop.
Save EastSideCode/25d20f2465d4b723665d64188d887617 to your computer and use it in GitHub Desktop.
Add html sitemap to pages
<div class="html-sitemap">
<h2>Author(s):</h2>
<ul class="sitemap-authors">
<?php
//http://codex.wordpress.org/Function_Reference/wp_list_authors
wp_list_authors('exclude_admin=1&optioncount=1');
?>
</ul>
<h2>Pages:</h2>
<ul class="sitemap-pages">
<?php
//http://codex.wordpress.org/Function_Reference/wp_list_pages
wp_list_pages('exclude=889&title_li='); //***Exclude page Id, separated by comma. I excluded the sitemap of this blog (page_ID=889).
?>
</ul>
<h2>Posts:</h2>
<ul>
<?php
//http://codex.wordpress.org/Function_Reference/get_categories
$cats = get_categories('exclude='); //***Exclude categories by ID, separated by comma if you like.
foreach ($cats as $cat) {
echo '<li class="category">'."\n".'<h3><span class="grey">Category: </span>'.$cat->cat_name.'</h3>'."\n";
echo '<ul class="cat-posts">'."\n";
//http://codex.wordpress.org/Function_Reference/query_posts
query_posts('posts_per_page=-1&cat='.$cat->cat_ID); //-1 shows all posts per category. 1 to show most recent post.
//http://us3.php.net/while ; http://codex.wordpress.org/The_Loop ; http://codex.wordpress.org/The_Loop_in_Action
//http://codex.wordpress.org/Function_Reference/the_time ; http://codex.wordpress.org/Function_Reference/the_permalink
//http://codex.wordpress.org/Function_Reference/the_title ; http://codex.wordpress.org/Function_Reference/comments_number
while(have_posts()): the_post();
//http://codex.wordpress.org/Function_Reference/get_the_category
$category = get_the_category();
//Display a post once, even if it is in multiple categories/subcategories. Lists the post in the first Category displayed.
if ($category[0]->cat_ID == $cat->cat_ID) {?>
<li><?php the_time('M d, Y')?> &raquo; <a href="<?php the_permalink() ?>" title="Permanent Link to: <?php the_title(); ?>">
<?php the_title(); ?></a> (<?php comments_number('0', '1', '%'); ?>)</li>
<?php } //endif
endwhile; //endwhile
?>
</ul>
</li>
<?php } ?>
</ul>
<?php
//http://codex.wordpress.org/Function_Reference/wp_reset_query
wp_reset_query();
?>
<h2>Archives:</h2>
<ul class="sitemap-archives">
<?php
//http://codex.wordpress.org/Function_Reference/wp_get_archives
wp_get_archives('type=monthly&show_post_count=true');
?>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment