Skip to content

Instantly share code, notes, and snippets.

@dajare
Created April 29, 2011 13:45
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 dajare/948315 to your computer and use it in GitHub Desktop.
Save dajare/948315 to your computer and use it in GitHub Desktop.
Tag page code for Wolf CMS plugin Tagger - inserts date values into archive page URLs
<?php
$pages = $this->tagger->pagesByTag();
if($pages){
echo "<h3>Pages tagged with '".$this->tagger->tag()."':</h3>";
echo '<ul>';
foreach($pages as $slug => $page) {
// set number in next line to total characters of URL up to first slug:
$pageslugs = substr($slug, 28);
// if archive page, put date slugs into URI:
if ($this->find($pageslugs)->parent()->behavior_id == 'archive') {
$slugarray = explode('/', $pageslugs); $starturi = reset($slugarray); $enduri = end($slugarray);
$uridate = $this->find($pageslugs)->date('%Y/%m/%d/');
echo '<li><a href="'. URL_PUBLIC . $starturi ."/". $uridate . $enduri . URL_SUFFIX .'">'.$page.'</a> ['. $this->find($pageslugs)->date() .']</li>';
// normal page, so normal URI:
} else {
echo '<li><a href="'.$slug.'">'.$page.'</a> ['. $this->find($pageslugs)->date() .']</li>';
}
}
echo '</ul>';
} else {
echo "<p>There are no items with this tag.</p>";
}
?>
@dajare
Copy link
Author

dajare commented Apr 29, 2011

Notes:

  1. In line 8, the number represents how many characters there are in the fully-formed URL up to and including the first slash after the site's root. Example: in http://example.com/blog/article, the number would be 19.
  2. That same line does not take into account any URL suffix; this would need to be stripped from the end of the fully formed URL (represented in the Tagger code by $slug).
  3. This code (line 11) assumes that "blog" articles are at level 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment