Jump to content

Recommended Posts

Posted

Hi,

I have init.php file where is called a lot of pages for links in the navigation. Navigation has dropdowns and the links are not placed the same as in the backend.

$variableone = $pages->get(1100);
$variablegtwo = $pages->get(1101);
$variablethree = $pages->get(1102);
$variablefour = $pages->get(1103);
...

Is there a better way to speed up this queries?

Posted

Depends on what 'lots of pages' amount to.

Assuming you know the IDs beforehand, one way you could do it.

<?php namespace ProcessWire;

$ids = [1100,1101,1102,1103];
$selector = implode("|",$ids);
$fields = ['id','title'];// depends on the fields you want; 'id' can also be left out in which case you get it as the key of each item
$items = $pages->findRaw($selector,$fields);// Array
// or if you need the pages
// $items = $pages->find("id={$ids}");// PageArray

Another way would be to cache the menu, if it is not dynamic..

Just a few thoughts.

  • Thanks 1
  • Leftfield changed the title to Best way to speed up queries pages find [SOLVED]
Posted
28 minutes ago, Leftfield said:

but caching menu is pretty good answer.

Here you have several options. Server-side, my favourite is WireCache ($cache variable). I am assuming you don't have ProCache. That would make your pages load even faster. You could also cache client-side on the browser.

  • Thanks 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...