Jump to content

Predefined field: create / show link to child page


neophron
 Share

Recommended Posts

Hi,

this is the website structure:

root
       -gardens
          -garden01
          -garden02
          -garden03
          -garden04
          -etc
       -contact
       -stuff

On the gardens site I'm looping part of the fields from the child pages (garden01, garden02 etc).

Some of the pages shall be linked from »gardens«, some not. I wanted to offer the editor a simple way to activate the link with one or to clicks.
What I tried, was a way via hanna code.
I created a hanna code with this code:

<a href="<?=$garden->url;?>">read more...</a>

I pasted this hannacode in a textfield (with hannacode formatter). This textfield is inside the foreach loop in the template from gardens. But the system gives me an error.
I was thinking with a checkbox field and hannacode, but with no success.

Do you guys have some experience with that?

Link to comment
Share on other sites

Just place a checkbox field (eg "showlink") on the garden template (child) and in your gardens template (parent) you list your pages:

// current $page is "gardens"
echo "<ul>";
foreach($page->children() as $child) {
	$link = $child->title;
	if($child->showlink) $link = "<a href='{$child->url}'>$link</a>";
  	echo "<li>$link</li>";
}
echo "</ul>";

 

Link to comment
Share on other sites

Thanks for your suggestion.

I placed a checkbox in the child template (not file) and pasted your code in the parent template. Then I checked the link in backend
The thing is, that this code must be inside a foreach loop.

The main loop starts with this:

<? foreach($page->children() as $garten):?>

After pasting your code, the front-end shows all subpages as a ul and this doesn't make sense. 

screenshot.thumb.jpg.f8c144a6ecc11b06d8423f5a50896a7c.jpg

 

I need only the link to the source (child) page. Usually I would paste this code for showing all links to the subpage: 

<a href="<?=$garten->url;?>">Weiterlesen...</a>

 

 

 readmore.thumb.jpg.f0411999d40177917351c0ffae2677e6.jpg

 

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