Jump to content

output in several pages


bbeer
 Share

Recommended Posts

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

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

$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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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