louisstephens Posted November 10, 2015 Share Posted November 10, 2015 I appreciate all the help thus far in learning how to navigate Processwire. However, I have hit a road block. I have an Image Field in one of my templates (it is being used in a repeater), and I would like to assign a preexisting page's url to the image . Ie: <a href="url-to-page"><img src="code-for-image" /></a> However, maybe I have missed something, as I set up the field (homepageImg) to be a "page select" but nothing is currently populating the dropdown. I am merely trying to get all the children of the parent (that the current page is in) and display them. I thought this would make it easy for someone to set the URL on the fly. Any help would be appreciated. Link to comment Share on other sites More sharing options...
cstevensjr Posted November 10, 2015 Share Posted November 10, 2015 If I understand you correctly, you now need a parent page in the tree where all of your "page selects" are pulled from. The child pages are what you see in your field (homepagimg). An Example Link to comment Share on other sites More sharing options...
kixe Posted November 11, 2015 Share Posted November 11, 2015 The following code snippet wraps an image with an anchor tag, if the first word of the image description matches a pagename of a page in your page tree $image = $page->images->first(); $selector = strstr($image->description,' ',true)?strstr($image->description,' ',true):$image->description; $selector = trim($selector,"\W"); // trim punctuation $linkpage = $pages->get('name='.$selector.',has_parent!=2'); // modify selector for your needs $anchor = $linkpage->id?"<a title=\"go to $linkpage->title\" href=\"$linkpage->url\">":null; echo "$anchor<img src=\"$image->url\" alt=\"$image->description\"/>".($anchor?'</a>':''); to get all siblings of your page use $pages->siblings($selector); Link to comment Share on other sites More sharing options...
louisstephens Posted November 11, 2015 Author Share Posted November 11, 2015 Thank you all for the quick responses. After rereading my original post, I think I need to clarify the issue. I have a repeater set up with: Name Image PageUrl (this is the field set to a page field). I thought by setting pageURL to a page field type, I could then select a page, and then pull that url using something similiar to what kixe describes. However, nothing is showing up in the actual dropdown. Is there a better way to allow a user to select a "url" to use for linking the image? Link to comment Share on other sites More sharing options...
cstevensjr Posted November 11, 2015 Share Posted November 11, 2015 I've used URLs before but those URLs were in the page title and that's how they were retrievable in the dropdown. You may be able to use an actual URL field and do the same thing. Link to comment Share on other sites More sharing options...
louisstephens Posted November 11, 2015 Author Share Posted November 11, 2015 Ah, This repeater will be used on other pages as well, so I was trying to figure out a way for the url selection to be easy on the user without having to manual input the url for every page. Link to comment Share on other sites More sharing options...
adrian Posted November 12, 2015 Share Posted November 12, 2015 Maybe I am not understanding, but it should be as simple as returning this: $homepageImg->url Just make sure that the homepageImg field is set to "PageListSelect" without the "Multiple" and that the "Dereference in API as" is set to Single. That should then return the URL to the page they selected. Link to comment Share on other sites More sharing options...
louisstephens Posted November 12, 2015 Author Share Posted November 12, 2015 Thanks Adrian. The idea in my head might not be coming out in the actual post as well as I intended. The basic set up is thus: I have an Image field in my template as well as a field called 'imageURL' (all in a repeater). My hopes were that I could easily use a drop down to allow a user to change the url of the image on the fly without having to manually enter the information. The page Structure I have is: Home - Sub Page 1 - Sub 'Sub' Page - Sub 'Sub' Page - Sub 'Sub' Page - Sub 'Sub' Page - Sub 'Sub' Page - Sub Page 1 For the url field, I was hoping to just grab the list of "Sub Sub Pages", and snag the url from that to link the image with. Link to comment Share on other sites More sharing options...
Peter Knight Posted November 12, 2015 Share Posted November 12, 2015 I think I had the same problem recently. I'll trawl through a project I had in progress and see how I solved it. You basically want to allow clients to apply a link to an image. The link around the image would direct front end users to an internal page. On the Admin side, you're using the pageselect field to achieve this. Any code examples and screenshots of the Admin for us? Link to comment Share on other sites More sharing options...
adrian Posted November 12, 2015 Share Posted November 12, 2015 Is this what you want to see? The other option would actually be to use the ImageExtra module and the link option - it will work like a pagelistselect, rather than a select dropdown, but would avoid the need for repeaters. Link to comment Share on other sites More sharing options...
louisstephens Posted November 12, 2015 Author Share Posted November 12, 2015 Thanks everyone. Adrian, that is what I am trying to achieve, and hopefully can extract the url from that. Ill try to get some pictures up to hopefully better explain. I do apologize for seeming so vague. Link to comment Share on other sites More sharing options...
adrian Posted November 12, 2015 Share Posted November 12, 2015 If my screenshot is what you want to achieve, then it's very easy. Here are the settings for the details tab of the field: And here is the page tree that is being referenced: 3 Link to comment Share on other sites More sharing options...
louisstephens Posted November 12, 2015 Author Share Posted November 12, 2015 Ah ha.. That does the ticket. And now for something probably too confusing. I know this method would only work for this repeater on this page. However, what If I wanted to reuse this repeater and its fields on another page tree all together (without recreating the repeater everytime). Link to comment Share on other sites More sharing options...
adrian Posted November 12, 2015 Share Posted November 12, 2015 Ah ha.. That does the ticket. And now for something probably too confusing. I know this method would only work for this repeater on this page. However, what If I wanted to reuse this repeater and its fields on another page tree all together (without recreating the repeater everytime). Depending on your setup, you could probably make use of the "Custom PHP code to find selectable pages" option and reference the $page->parent or $page->parent->parent - hopefully you get the idea. 2 Link to comment Share on other sites More sharing options...
louisstephens Posted November 13, 2015 Author Share Posted November 13, 2015 Perhaps a dumb question Adrian, I see that return $page->parent->parent(); returns the top level so: - Sup Page 1 - Sup Page 2 - Sup Page 3 - Sup Page 4 How would I drill down and list all the children of the parent? I know about first();, but didnt know if there was an "All" selector. I do appreciate all the help as I stumble through this. Link to comment Share on other sites More sharing options...
adrian Posted November 13, 2015 Share Posted November 13, 2015 return $page->parent->parent->children(); Link to comment Share on other sites More sharing options...
louisstephens Posted November 16, 2015 Author Share Posted November 16, 2015 Thanks Adrian. I actually had gotten to that point yesterday, but noticed it was still pulling in the parents. I got it working with: return $page->parent->children(); 1 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