Skip to content

Instantly share code, notes, and snippets.

@joeworkman
Last active March 16, 2019 02:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeworkman/d18a10966c9c85c802bcbe9afdfc1822 to your computer and use it in GitHub Desktop.
Save joeworkman/d18a10966c9c85c802bcbe9afdfc1822 to your computer and use it in GitHub Desktop.
This will create a Total CMS menu of categories/tags/authors with a submenus of all posts in that are assigned to that category/tag/author
<?php
$cmsid = "blog";
$attribute = "category"; // tag, category, author
$href = "/blog/?category="; // URL to blog list with category filter
//-----------------------------------------------
// Do not modify below this line
//-----------------------------------------------
if ($publish) {
$totalblog = new \TotalCMS\Component\Blog($cmsid);
$attrs = $totalblog->list_attributes($attribute);
foreach ($attrs as $attr) {
$perm = explode("=",$attr["params"])[1];
$label = $attr["label"];
echo "<li class='has-dropdown'><a href='$href$perm'>$label</a><ul class='dropdown'>";
$posts = $totalblog->filter_posts([$attribute=>$perm]);
usort($posts, function($a, $b){
return strcmp($a->title, $b->title);
});
foreach ($posts as $post) {
echo "<li><a href='$totalblog->posturl$post->permalink'>$post->title</a></li>";
}
echo "</ul></li>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment