Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get a list of available pages from pages.array
#1
I have a one-page site in development and would like to automate a component which I place on the page via the DynPages plugin. Said component holds the markup for the in-page sections which are output to the page via the SimplePageContent plugin.

I did some research on the forums here and found two related threads, but I have to admit that I don't grok the menu_data() function. I then thought maybe the pages.array file generated for caching might help since I would "merely" have to extract the available pages.

My current, manually updated, structure looks like the following (basically the same for each section on the page):

Code:
<div id="seite-info">
<h2><?php getPageField('info',title); ?></h2>
<?php echo get_page_by_id('info'); ?>
</div>

Can someone give me a few pointers on how to extract a page list from the pages cache in 3.1b? I think I'll need an array of slugs which I can loop through and populate the above mini template with.

Help is much appreciated.
Reply
#2
The internal caching makes all the data available into a global array $pagesArray for use on your pages.

So you can just loop through it like so:

Code:
function listPages(){
    global $pagesArray;
     foreach ($pagesArray as $page) {
         echo '<div id="seite-info">';
        echo '<h2>'.$page['title'].'</h2>';
        echo get_page_by_id('info');
        echo '</div>';
    }
}

MIke,.
My Github Repos: Github
Website: DigiMute
Reply
#3
I basically got it to work with your help, thanks so far! What I can't fix yet is that the array doesn't list the pages in the order that they appear in the navigation. So my content is tossed around the page.

Edit: print_r() for the win! I'll try and sort by [menuOrder].
Reply
#4
updated code should do it for you...

Code:
function listPages(){
    global $pagesArray;
$pages= subval_sort($pagesArray,'menuOrder');  // can now take a 3rd option 'asc' or 'desc' for sorting..
     foreach ($pages as $page) {
         echo '<div id="seite-info">';
        echo '<h2>'.$page['title'].'</h2>';
        echo get_page_by_id('info');
        echo '</div>';
    }
}

MIke,.
My Github Repos: Github
Website: DigiMute
Reply
#5
Unfortunately, it doesn't, Mike. :/

Now there's no output at all here and an print_r($pages) outputs nothing either. Tried putting a global $menuArray; at the top as well, to no avail.

Been researching arrays, their sorting, etc. for an hour now, only slowly getting a grip on this.
Reply
#6
The following seems to work

Code:
<?php
function listPages(){
        global $pagesArray;        
        $pages= subval_sort($pagesArray,'menuOrder');  // can now take a 3rd option 'asc' or 'desc' for sorting..
        
         foreach ($pages as $page) {
            echo '<div id="' . $page['slug'] . '">';
              echo '<h2>' . $page['title'] . '</h2>';
              echo get_page_by_id($page['slug']);
            echo '</div>';
        }
}
?>

I just replaced $menuArray with $pagesArray.
Reply
#7
Oops, sorry copy/pasted from some code , never check the vars...
My Github Repos: Github
Website: DigiMute
Reply
#8
Hi,


Is there a way to loop like this only into pages of a certain language?



Thanks!
Reply
#9
Since the language is tied to the suffix of the slug (e.g. index_de), you can perhaps try parsing that:

PHP Code:
// Initialize some variables to be used in the loop
$langSuffix  '_de'// your language

// Main loop
foreach ($pages as $page) {
  
// check that the language suffix in the slug
 
 if (strpos($page['slug'], $langSuffix) !== -1) {
 
   // Do something with this language-specific page
 
   // ...
 
 }
 
 // ...


(Not tested yet)
Reply




Users browsing this thread: 1 Guest(s)