Jump to content

Related pages


Marty Walker
 Share

Recommended Posts

Hi,

I've setup a related pages type field using ASMselect. It all works fine, the problem as per usual is my code (which mostly works):

<?php
	if($page->related_pages) {
echo "<h2>Related pages:</h2><ul>";
	foreach($page->related_pages as $related_page) {
		echo "<li>{$related_page->title}</li>";
		}
		echo "</ul>";
	}

The only issue I have is that if I don't select any related pages my H2 still appears.

Regards

Martin

Link to comment
Share on other sites

Never mind I got it:

<?php
	if($page->related_pages != '')...

I'm thinking that would only work if your related_pages field was set with this (in the details tab when editing your related_pages field):

Dereference in API as: Single page (Page) or boolean false when none selected

So it confuses me that your example was cycling multiple pages when it would appear that you have a single page field set to return false when empty. Either that, or PHP uses the Countable interface in typecasting to boolean comparisons (can't say as though I've tried). In either case, you may want to choose this instead, if haven't already:

Dereference in API as: Multiple pages (PageArray)

And code it like this:

<?php
if(count($page->related_pages)) {
    echo "<h2>Related pages:</h2><ul>";
    foreach($page->related_pages as $related_page) {
        echo "<li>{$related_page->title}</li>";
    }
    echo "</ul>";
}
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...