I've created a tags field so that the CMS user may add tags to blog posts that then link to a list of all the posts with that tag:
Reading out tags from all post pages:
<?php
$matches = $pages->find("template=post");
$tags = array();
foreach($matches as $key => $tag){
foreach(explode(",", $tag->tags) as $key => $t) {
$tags[$t] = str_replace(' ','',$t);
}
}
$tagsClean = array_unique($tags);
sort($tagsClean);
foreach($tagsClean as $word){
//if not blog page creat links to search from the blog
if($page->path == '/blog/'){
echo '<a href="?topic=' . $word . '">';
}else{
echo '<a href="../?topic=' . $word . '">';
}
echo $word;
echo '</a><br />';
}
I'm now trying to work out how to list those pages which have the same tag as the current page (related posts):
as far it only lists what tags the current page does have:
<?php
$pageTags = array();
foreach(explode(",", $page->tags) as $key => $t) {
$pageTags[$t] = str_replace(' ','',$t);
}
$pageTagsClean = array_unique($pageTags);
sort($pageTagsClean);
foreach($pageTagsClean as $pageTag){
echo '<a href="../?topic=' . $pageTag . '">';
echo $pageTag;
echo '</a><br />';
}
Any help would be great, thanks