alanxptm Posted November 15, 2019 Share Posted November 15, 2019 Hi I want to list the latest articles on the site, the articles have multiple templates using the same template php archive. I have tried with: $pages->find('template=lvl04-post, limit=5'); but didn't work. Also, I have read about $template->filename, but don't understando how to use it with find() Articles and parent categories have their own single templates because of role permissions, so I can't just do a normal 'template=name' This is the full code: <?php $posts = $pages->find('template=phpfilename?, limit=5'); foreach($posts as $post){ ?> <a href="<?php echo $post->url; ?>"><?php echo $post->title; ?></a><br /> <?php echo date("d/m/Y", $post->published); ?><br/> <?php echo $post->resume; ?><br/> <?php } ?> Any help is appreciated ? Link to comment Share on other sites More sharing options...
Jonathan Lahijani Posted November 15, 2019 Share Posted November 15, 2019 That code seems correct. Are any of the post pages in-fact published, because if not, you'll need to add 'include=all' to your selector: $pages->find('template=lvl04-post, limit=5, include=all'); 1 Link to comment Share on other sites More sharing options...
alanxptm Posted November 15, 2019 Author Share Posted November 15, 2019 I mean "lvl04-post.php" pages have other Processwire templates, like: cat01-post, cat02-post, cat03-post, etc. Link to comment Share on other sites More sharing options...
Robin S Posted November 15, 2019 Share Posted November 15, 2019 Try: // Set filename manually $filename = $config->paths->templates . 'lvl04-post.php'; // Or get filename from one of the templates that uses it // $filename = $templates->get('lvl04-post')->filename; // Find templates that use this template file $tpls = $templates->find("filename=$filename"); // Find pages using those templates $posts = $pages->find("template=$tpls, limit=5"); 5 Link to comment Share on other sites More sharing options...
alanxptm Posted November 15, 2019 Author Share Posted November 15, 2019 Sadly it didn't work, but I've already changed all the site and template structure so I can find by the single template name. I suppose is the best way, but would like to have the option to find by archive name, as it is an option in the template settings ? Link to comment Share on other sites More sharing options...
Robin S Posted November 15, 2019 Share Posted November 15, 2019 22 minutes ago, alanxptm said: Sadly it didn't work It works for me, so double-check your code. Another way you can find related templates is to apply a tag to them in the admin (Advanced tab). Then you can find the templates that have that tag and find pages using those templates. // Find templates with tag "foo" $tpls = $templates->find("tags=foo"); // Find pages using those templates $items = $pages->find("template=$tpls"); 2 Link to comment Share on other sites More sharing options...
alanxptm Posted November 29, 2019 Author Share Posted November 29, 2019 I just needed this again and this time I've found a simple solution.. I was so focused on PW functions instead of plain PHP ? $tmplt = basename($page->template->filename,'.php'); 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