Leftfield Posted October 2, 2021 Share Posted October 2, 2021 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? Link to comment Share on other sites More sharing options...
kongondo Posted October 2, 2021 Share Posted October 2, 2021 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. 1 Link to comment Share on other sites More sharing options...
Leftfield Posted October 2, 2021 Author Share Posted October 2, 2021 @kongondoI was thinking that exporting to JSON would be faster but caching menu is pretty good answer. 1 Link to comment Share on other sites More sharing options...
kongondo Posted October 2, 2021 Share Posted October 2, 2021 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. 1 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