bbeer Posted February 21, 2014 Share Posted February 21, 2014 Hi I like to output a page in several other pages I can call the content in a single page but I'm stuck with multiple pages. <?php $downloads = $pages->get("1114"); if ($page->id == '1011'){ echo "$downloads->body"; } ?> Link to comment Share on other sites More sharing options...
adrian Posted February 21, 2014 Share Posted February 21, 2014 The key is find vs get: $downloads = $pages->find("id=1|1114|1452"); foreach($download as $p){ echo $p->body; } EDIT: Actually I am not quite sure what you are trying to achieve. I left out the check for whether the current page is id=1011, but you can easily add that back into my code. Am I on the right track with grabbing the content of pages using multiple IDs in the find, or am I off track completely with what you want? 1 Link to comment Share on other sites More sharing options...
bbeer Posted February 21, 2014 Author Share Posted February 21, 2014 Thanks Adrian I think I need it the other way round I get page 1114 and want to output it in 1010, 1011, 1022 the template is used for many page but I want to output downloads on some of them. Link to comment Share on other sites More sharing options...
adrian Posted February 21, 2014 Share Posted February 21, 2014 $downloads = $pages->get("1114"); if ($page->id == '1010' || $page->id == '1011' || $page->id == '1022'){ echo "$downloads->body"; } 1 Link to comment Share on other sites More sharing options...
bbeer Posted February 21, 2014 Author Share Posted February 21, 2014 Adrian thanks a lot, perfect! Link to comment Share on other sites More sharing options...
adrian Posted February 21, 2014 Share Posted February 21, 2014 No problem, another alternative would be: $pids = array(1010, 1011, 1022); $downloads = $pages->get("1114"); if (in_array($page->id, $pids)){ echo "$downloads->body"; } This would be cleaner if your list of pages started getting longer. 4 Link to comment Share on other sites More sharing options...
bbeer Posted February 21, 2014 Author Share Posted February 21, 2014 great, a lot better readable like this. Thanks again. Link to comment Share on other sites More sharing options...
horst Posted February 21, 2014 Share Posted February 21, 2014 $pids = array(1010, 1011, 1022); $downloads = $pages->get("1114"); if (in_array($page->id, $pids)){ echo "$downloads->body"; } @adrian: if the actual page isn't in $pids, there is no need to load page 1114 into memory $pids = array(1010, 1011, 1022); if(in_array($page->id, $pids)) { $downloads = $pages->get("1114"); echo "$downloads->body"; } 4 Link to comment Share on other sites More sharing options...
adrian Posted February 21, 2014 Share Posted February 21, 2014 Nice catch horst Can I go one simpler: $pids = array(1010, 1011, 1022); if(in_array($page->id, $pids)) { echo $pages->get("1114")->body"; } or even just: if(in_array($page->id, array(1010, 1011, 1022))) echo $pages->get("1114")->body"; 4 Link to comment Share on other sites More sharing options...
diogo Posted February 23, 2014 Share Posted February 23, 2014 even shorter if(in_array($page->id, [1010, 1011, 1022])) echo $pages->get("1114")->body"; Edit: only in PHP 5.4 2 Link to comment Share on other sites More sharing options...
adrian Posted February 23, 2014 Share Posted February 23, 2014 Hey diogo - not sure, but I don't think that works in php <5.4 does it? Link to comment Share on other sites More sharing options...
diogo Posted February 23, 2014 Share Posted February 23, 2014 You're too fast. I had just edited my post 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