Roych Posted December 10, 2020 Posted December 10, 2020 Hello I'm having some troubles getting first image from pages selected with page reference field. I have categories with children and each children has one image (images field). Then on Posts page I have page reference field for selecting and adding those categories. I can echo the title based on selection but somehow can't get images to show up. What am I doing wrong here? <?php echo $page->skupine_page_select->implode(function($item) { return " <a rel='tag' href='$item->url'>#$item->title <img src='$item->images()->url'></a>"; }); ?> Thank you for your help R
kongondo Posted December 10, 2020 Posted December 10, 2020 This doesn't look right. <?php $item->images()->url; From the looks of it, $item is a page. You are then calling a method on images() which does not exist for Page objects. If your field is called images, then change it to this if it is a single image field: <?php $item->images->url; OR, if it is a multi-image field: <?php $item->images->first()->url;
Roych Posted December 10, 2020 Author Posted December 10, 2020 sorry, my mistake I already tried it with $item->images->first()->url I mistyped in above post. When reading my first post I I wasn't realy clear about what I wan't. Sorry ? My page tree: BLOG (template = blog-list) - Post 1 (template = blog-detail) - with page reference field "skupine_page_select" (bullets for selecting category for each post) - Post 2 -"- - Post 3 -"- CATEGORIES (template = categories-List) - Category 1 (template = category-detail) with image field - Category 2 -"- - .... I want to show category image in my "blog-detail" template. I can bring the title of the category but not the image. This shows the title, but I guess it is just from the page reference field itself which is already in my blog-detail template, or ...? <?php echo $page->skupine_page_select->implode(function($item) { return " <a href='$item->url'>$item->title</a>"; }); ?> I hope you understand Thank you
kongondo Posted December 10, 2020 Posted December 10, 2020 (edited) I need to sleep and I need to test this..ignore previous post ?. Edited December 10, 2020 by kongondo clarification
kongondo Posted December 10, 2020 Posted December 10, 2020 Curly braces...around {$item->images->first()->url} <?php <a rel='tag' href='$item->url'>#$item->title <img src='{$item->images->first()->url}'></a>"; 1
Roych Posted December 10, 2020 Author Posted December 10, 2020 2 hours ago, kongondo said: Curly braces...around {$item->images->first()->url} <?php <a rel='tag' href='$item->url'>#$item->title <img src='{$item->images->first()->url}'></a>"; Omg, not even sure what to say, lol? Didn't thought of them. Works perfect now ? Thank you R
kongondo Posted December 10, 2020 Posted December 10, 2020 1 hour ago, Roych said: Works perfect now ? Good to know; excellent!
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