Jump to content

Recommended Posts

Posted

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 ?

Posted

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');

 

  • Like 1
Posted

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");

 

  • Like 5
Posted

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 ?

Posted
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");

 

  • Like 2
  • 2 weeks later...
Posted

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');

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...