Jump to content

Output based on second level


asbjorn
 Share

Recommended Posts

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.)

Link to comment
Share on other sites

some example code from a project for the level stuff:

// If the page has children, then render navigation to them under the body.
// make layout twocol and get some sidebar
$level = count($page->parents);
if ($page->template != "start") {
	if($page->hasChildren || $page->siblings && $level == 2) {
		$myLayout = "twocol";
		$sidebar = "<p>".$page->sidebar_content."</p>";
	}
}

so you can setup your $level and be sure that there are children...

best regards mr-fan

Link to comment
Share on other sites

If I'm understanding correctly, it sounds like all you need to do is pull the title of the parent's parent page. So, something like this:

<?= $new->parent->parent->title ?>

For the current item should output the title of the site page.

Or:

<?= $new->parents->get('template=sitePageTemplateName')->title ?>

 might work if you don't want to have to specify exactly how many levels above your site page is. That will search all parents of the page until it finds the one with the specified template.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...