davo Posted September 6, 2013 Share Posted September 6, 2013 I'm fairly new to pw but starting to get it. My biggest issue is probably trying to explain my question, which is probably why I've not been able to search for an answer as I'm sure it's explained somewhere. I have a page with a number of text fields. The last field on the page is Town. This is a page type field that refers to a number of other pages called Towns. The town pages consist of a title field and a country field, which is another page selector type. I know this is briefly touched on in the video tutorial but doesn't quite cover what I'm trying to do. So I'm trying to display the first page with it's fields including the Town. So I would call it in the template like this: echo $page->myfield echo $page->myotherfield but when it comes to town i tried this: echo $page->town but it returns the page ID I think when it renders the template. Which I sort of understand, it does know which field to display so it displays the page id. So how do I tell it to display the first field Title of that second page? Link to comment Share on other sites More sharing options...
diogo Posted September 6, 2013 Share Posted September 6, 2013 Not completely sure of what you want. I'm assuming that your pages fields accept only a single page, so this should work: echo $page->town->title // title of chosen town echo $page->town->country->title // title of chosen country inside the chosen town edit: corrected typo 3 Link to comment Share on other sites More sharing options...
davo Posted September 6, 2013 Author Share Posted September 6, 2013 Not completely sure of what you want. I'm assuming that your pages fields accept only a single page, so this should work: echo $page->town->title // title of chosen town echo $page->town_>country->title // title of chosen country inside the chosen town Thank you. I'll try that a little later today and post back exactly what I get. Link to comment Share on other sites More sharing options...
davo Posted September 6, 2013 Author Share Posted September 6, 2013 unfortunately that didn't work for me. So i've put a couple of lines below and the out put so maybe you can help me understand what's happening and how I can achieve what is probably very simple. 1<? echo $page->town_select->title; ?><br /> 2<? echo $page->town_select->county; ?><br /> 3<? echo $page->town_select->county; ?><br /> 4<? echo $page->town->title; ?><br /> 5<? echo $page->town; ?><br /> 6<? echo $page->town_select; ?><br /> 7<? echo $page->town_select->Title; ?><br /> and this is the output I get: 12345610117 As you can see "6<? echo $page->town_select; ?><br />" is the only line that returns anything. Output is held here: http://www.garagesalefinder.co.uk/listing-parent/crazy-garage-sale/ My primary page includes the field town_select, this holds a single page selection where the town name is held in the 'title' field. Link to comment Share on other sites More sharing options...
davo Posted September 6, 2013 Author Share Posted September 6, 2013 SORRY My fault entirely I'd set it to hold a number of pages - when changed to single page it now works. Also, i'd spelt county with a capital C not c. Changed that, and it works too. Thanks for your help. I'm sure I'll be back soon Link to comment Share on other sites More sharing options...
kongondo Posted September 6, 2013 Share Posted September 6, 2013 Davo, Welcome to PW and the forums. Note that if you have multiple pages or images in a field, PW will return an array. Hence, you would need to loop through them. Many people use foreach to loop through such arrays. 1 Link to comment Share on other sites More sharing options...
davo Posted September 7, 2013 Author Share Posted September 7, 2013 Thank you. That's actually what I was doing to retrieve the one and only first loop, I just knew there must have been an easier way to access a single row. I'd just forgotten to tell it in the setup that the field should only accept single choices not multiple. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now