I want to create a one-page website. What I hope to be able to do is load all the created pages from one content type under each other, prefably in a for each loop.

So in page.tpl.php it would be something like:

foreach($pages as $page){
    print $title;
    print render($page['content']);

This way I could also bind views/blocks to certain pieces of the page. The reason I'm looking for this kind of approach is to keep the website manageable.

The structure would be as follows:

 - slide one (view)
 - slide two (view)
 - slide three (view)
other page
 - slide one (view)
 - slide two (view)

So the mentioned slides are items from a different content type, loaded from a view.

If someone can point me in the right direction, or if some pieces of the question need clearing up, please let me know.

If people are still interested in this, I will give my solution here:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->propertyCondition('status', 1) /* Status to make sure it is published */
  ->propertyCondition('type', array('page', 'webform')) /* get pages and webforms */
  ->fieldOrderBy('field_volgorde', 'value', 'ASC') /* a custom field to set the order */
  ->range(0, 9999); /* amount of pages to get */
$result = $query->execute();
$nodes = node_load_multiple(array_keys($result['node']));

foreach($nodes as $node): 
    // Do your code magic

Within the foreach, fields can be echoed by using the following code examples:

echo $node->title;
echo $node->body['und'][0]['value'];
// ['und'] = language undefined

If there are any questions, feel free to let me know.


Create a custom content type with a textarea field for each section of the page (home, about, other).

Create a custom template for you content type and output all of the fields in the proper places. You can add your views as blocks.

Make sense?

  • It makes sense, but how would I go about outputting the fields in the proper places? Plus, would this also work with multiple pages. Say, if I would add more pages, could I then dynamically be able to add views as blocks to that? – Sander Koedood Sep 6 '13 at 14:51
  • you can you page--front.tpl.php as your template since it's your front page. – Scott Joudry Sep 6 '13 at 14:54
  • Could you give a code example how I would be able to load all pages after each other? I need to be able to give the different pages their own blocks/view-blocks and I get your story, up until the part how this all should get outputted. – Sander Koedood Sep 9 '13 at 12:14
  • After reading your suggestion again for the 10th time, I finally understand what you mean. I think that it's a good idea. The only downside is that you can't dynamically add new regions for new pages. – Sander Koedood Sep 18 '13 at 14:34

I use the following code to retrieve all nodes of a type:

$type = 'example';
$query = db_select('node', 'n')
  ->fields('n', array('nid'))
  ->condition('type', $type)
  ->condition('status', 1);
$nids = $query->execute()->fetchCol();
$nodes = node_load_multiple($nids);

I ended up using the following code to get all pages:

$type = "page"; // machine name for Basic Page
$nodes = node_load_multiple(array(), array('type' => $type)); 
foreach($nodes as $node):
    // code here
  • Just want to mention that node_load is the performance worst nightmare.. – rreiss Sep 10 '13 at 15:49
  • What would you recommend instead then? – Sander Koedood Sep 11 '13 at 13:12
  • I still didn't understand why not using views? Any way if you have a large number of nodes consider to use ajax to load the nodes - all depends on the amount of loaded content. If your method works fine (perfomance prespective) then use node_load. Think about possible changes in the future as well (adding video and view fields in that content type means a lot more server side calculations, adding mass amount of nodes to homepage, etc..) – rreiss Sep 11 '13 at 15:37
  • The problem with views is that some parts of my content have views of their own. And since you can't load a view in a view (for as far as I know), I get stuck there. All pages get loaded, and some pages have sub-pages, which need to be visible in the content. I see no possibility in doing that with views. – Sander Koedood Sep 12 '13 at 15:51
  • I used a view to display a content type with a view field in one of our projects, have you tried it or you just assumed it can't work? – rreiss Sep 12 '13 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.