Skip to content

Instantly share code, notes, and snippets.

@djave-co
Created September 18, 2015 13:14
Show Gist options
  • Save djave-co/d2f6fd9c20224f2f642d to your computer and use it in GitHub Desktop.
Save djave-co/d2f6fd9c20224f2f642d to your computer and use it in GitHub Desktop.
<?php
/*--------------------------------
|* Grab the sub pages
|*------------------------------- */
$sub_pages = new WP_Query(
array(
'post_parent' => $post->ID,
'post_type' => 'page'
)
);
$sub_page_posts = $sub_pages->posts;
/*--------------------------------
|* Sort out the tags.
|*------------------------------- */
$tag_ids = [
[
'slug' => 'all',
'name' => 'All'
]
];
foreach( $sub_page_posts as $sub_page):
$sub_page->tags = get_the_tags( $sub_page->ID );
/*--------------------------------
|* Create an empty var to hold
|* all the slugs to add as a class
|*------------------------------- */
$sub_page->tag_classes = ['filterable'];
if($sub_page->tags):
foreach($sub_page->tags as $tag):
/*--------------------------------
|* Add the tag to the var
|*------------------------------- */
$sub_page->tag_classes[] = $tag->slug;
/*--------------------------------
|* And, if we don't have it,
|* store what we need for the menu
|*------------------------------- */
if( ! array_key_exists($tag->term_id, $tag_ids)):
$tag_ids[$tag->term_id] = [
'slug' => $tag->slug,
'name' => $tag->name
] ;
endif;
endforeach;
endif;
endforeach;
?>
<div class="sidebar-module">
<h6>Categories</h6>
<nav class="no-bullets side-ruled-menu">
<ul id="filters">
<?php if($tag_ids): ?>
<?php foreach($tag_ids as $tag): ?>
<li><a href="<?php echo home_url('/') . '?tag=' . $tag['slug'] ;?>" data-tag="<?php echo $tag['slug']; ?>"><?php echo $tag['name']; ?></a></li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</nav>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment