I have a site with multiple subsites (for sub-organization under our main organization) on the same install. Simple stuff really, and useful because I have news/events that these have sub-organizations have common. Therefore I also have common categories. But I want to tag the news based on where their main location is. (So that people now they will be directed to another sub-organization if they click on a link with a tag).
My site structure:
Home
-Site A
--News
-Site B
--News
-Site C
--News
-Categories
--Cat 1
--Cat 2
On each site (Site A, Site B and Site C), I have a code for foreaching selected categories, it goes like this:
<?php
$ids = $page->show_news_cat;
$nnow = time();
$news = $pages->find("template=news-post, show_news_cat={$ids}, limit=3, date_publish<$nnow");
foreach ($news as $new)
// If unpublish has a date
if($new->date_unpublish != "") {
if(time() > $new->getUnformatted('date_unpublish')) {
$new->of(false);
$new->addStatus(Page::statusHidden);
$new->save();
}
}
echo
"<div class='col-md-4'>" .
"<a href='{$new->url}'><h2>{$new->title}</h2></a>" .
date("d. F Y", $new->date_publish) .
"</div>"
;
?>
E.g. I would want to tag news located in Home>Site A>News with "Site A", if I am currently browsing on Site B or Site C.
I looked around the forum and tried this and that, but with no luck.
If nothing fancy works, I could always have my code check if url/path for each news contains "site-a" or "site-b", and then output something based on that. But I never found the right functions for that.
Could someone help to point me in the right direction. (IF you have other comments on the code above, I am not one for saying no thanks to improvements. I never learnt php proper.)