Jon E Posted November 25, 2014 Share Posted November 25, 2014 Hi, So I am creating a portfolio site and am using my homepage as a way of displaying images (so images added to that entry). Is there a way I can create a tag page, so that I can add a page elsewhere on the site, and the user can enter into a field the tag of images they want to show there that are uploaded to the homepage entry. So, I'm trying something like the below: <?php include("./head.inc"); ?> <div id="client_body"> <h1>Tag view title</h1> <h2><?php echo $page->get("title"); ?></h2> <?php if($page->tag_name):?> <h2><?php echo $page->get("tag_name"); ?></h2> <?php endif; ?> <?php foreach($page->images as $image) { // retrieve first image with tag 'mytag' $image = $page->images->getTag('mytag'); echo "<img src='$image->url'>"; } ?> <?php include("./foot.inc"); ?> Thanks, does this make sense? Jon Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 25, 2014 Share Posted November 25, 2014 Your pictures are on the homepage. But this code seems to be from a different template. So you need to call your images from the right page - the homepage. … $homepage = $pages->get("/"); //get the homepage foreach($homepage->images as $images) … Link to comment Share on other sites More sharing options...
Jon E Posted November 25, 2014 Author Share Posted November 25, 2014 Thanks, that works. But say if I want the tag its pulling from to be dynamic, so I use the 'tag_name' field within this code to show whatever I propose in the admin panel, how may I go about doing that? Also for some reason I only get one image appearing at the moment... Sorry thanks so much. <?php include("./head.inc"); ?> <div id="client_body"> <h1>Client Area</h1> <h2><?php echo $page->get("title"); ?></h2> <?php if($page->tag_name):?> <h2><?php echo $page->get("tag_name"); ?></h2> <?php endif; ?> <?php $homepage = $pages->get("/"); //get the homepage foreach($homepage->images as $image) // retrieve first image with tag 'mytag' $images = $homepage->images->getTag('tag'); echo "<img src='$image->url'>"; ?> <?php include("./foot.inc"); ?> Link to comment Share on other sites More sharing options...
Jon E Posted December 11, 2014 Author Share Posted December 11, 2014 Hi, Do you think anyone would be able to help me with this? So I want to output a certain tag that is specified in a field for this page from images tagged as such from the homepage... Thanks so much Link to comment Share on other sites More sharing options...
Peter Knight Posted December 11, 2014 Share Posted December 11, 2014 Have I got this right? You have a portfolio section in PW. It consists of several Projects and each project is a Page. Projects - project a - project b - project c On each Project field, you have the followign fields Title Image Tag Body etc You then want to pull 1 or more projects onto the homepage and display just the contents of these fields Title Image Tag Link to comment Share on other sites More sharing options...
Jon E Posted December 11, 2014 Author Share Posted December 11, 2014 Almost. I have all of the images in the images field on the homepage. I then have a page called 'clients', which is blank. For each child of this page I want to enter the tag into a field, so on a client child page I enter 'portrait' and it shows all images from the homepage that are tagged with 'portrait'. Does this make sense? Thanks so much Link to comment Share on other sites More sharing options...
kongondo Posted December 11, 2014 Share Posted December 11, 2014 (edited) Writing quickly but these should point you in the right direction...to implement in your code above // retrieve all images with tag 'potrait' $images = $page->images->findTag('potrait'); you can then iterate $images. If in a selector, then search using the subfield tags: // Find pages containing an image with the single (1) tag: 'potrait' // This will only match images with 1 single tag of 'potrait'. $mypages = $pages->find("images.tags=potrait"); http://processwire.com/api/fieldtypes/images/ Btw, just wondering why your tags have to be manually entered in some field? Why not use the child pages themselves as tags? Then you can use pagefields to pull in those tags? E.g. a child paged titled 'potrait' Edited December 11, 2014 by kongondo Link to comment Share on other sites More sharing options...
Peter Knight Posted December 11, 2014 Share Posted December 11, 2014 Almost. I have all of the images in the images field on the homepage. I then have a page called 'clients', which is blank. For each child of this page I want to enter the tag into a field, so on a client child page I enter 'portrait' and it shows all images from the homepage that are tagged with 'portrait'. That's interesting. I do it the other way around as to me, the homeage consists of contents from deeper within the site. 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