Jump to content

Show field of related page


mds
 Share

Recommended Posts

Getting started with ProcessWire and not much off PHP experience …

I've set up a field with authors, which shows a dropdown select of users on my blog entry page. So, in the admin everything works fine.

Now I want to show the author on my blog entry page/ php-template. But in the output it only shows the page id, when I use 

<?php echo $page->author ?>

How do I show a different field from that page, for instance the full name or how do I use the URL of the first image on that User page?

I thought it would as simple as 

<?php echo $page->author->fullname ?>

 

Link to comment
Share on other sites

Looks like your field is returning an array of author options, so try:

<?php echo $page->author->first()->fullname ?>

You can also use: last(), or eq(n)

The other approach is to foreach through each author:

foreach($page->author as $author) {
	echo '<p>'.$author->firstname.'</p>;
}

 

  • Like 1
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...