Jump to content

Recommended Posts

Posted

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";
    }   
    ?>
Posted

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?

  • Like 1
Posted

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.

Posted
$downloads = $pages->get("1114");   
if ($page->id == '1010' || $page->id == '1011' || $page->id == '1022'){
    echo "$downloads->body";
} 
  • Like 1
Posted

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.

  • Like 4
Posted
$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";
}
  • Like 4
Posted

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";
  • Like 4
Posted

even shorter :)

if(in_array($page->id, [1010, 1011, 1022])) echo $pages->get("1114")->body";

Edit: only in PHP 5.4

  • Like 2

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...