Jump to content
Sign in to follow this  
aren

Building a tumblr-style website

Recommended Posts

Hey guys,

I was wondering if it's possible to build a Tumblr-style website with ProcessWire. Sections/pages would be Article, Image, Video, Audio and Quote. But how can I get the posts from all of them (ordered by date as in a blog) in the homepage?

Many thanks for any help!

Share this post


Link to post
Share on other sites
$allArticles = $pages->find("template=article|image|video|audio|quote, sort-=created, limit=20");

foreach($allArticles as $article) {
  echo $article->render();
}
  • Like 2

Share this post


Link to post
Share on other sites

Hi apeisa, thanks for such a quick reply! :)

So I don't have to include the templates "articles.php", "images.php" and so on.. in the code? 

Oh, and can you please tell me what the "render" in the code does?

Share this post


Link to post
Share on other sites

Hi apeisa, thanks for such a quick reply! :)

So I don't have to include the templates "articles.php", "images.php" and so on.. in the code? 

Oh, and can you please tell me what the "render" in the code does?

Each type of articles must have it's own template. "Render" makes output depending on different templates.

Share this post


Link to post
Share on other sites
$allArticles = $pages->find("template=article|image|video|audio|quote, sort-=created, limit=20");

foreach($allArticles as $article) {
  echo $article->render();
}

For crying out loud! How easy is this system! Only 3 lines of code. PW has spoiled us all! :)

Oh, and can you please tell me what the "render" in the code does?

In other words, render outputs those pages including their templates files markup (i.e. not just their field values). The one thing you need to be mindful of (if I remember correctly) is to construct the HTML in those template files (assuming they have HTML) properly so that your rendered pages do not end up with duplicate HTML elements where you should only have one-pair tags, e.g. <body></body><body></body>, head, etc..Only include the markup you need...

Edited by kongondo
  • Like 1

Share this post


Link to post
Share on other sites

To avoid any duplication kongondo is talking: In latest versions (not sure if in stable yet), you can do this:

$allArticles = $pages->find("template=article|image|video|audio|quote, sort-=created, limit=20");

foreach($allArticles as $article) {
  $templateFile = $article->template . "-teaser.php";
  echo $article->render($templateFile); // It renders the content with article-teaser.php, image-teaser.php etc...
}

There is of course multiple ways of doing that (I rarely output any markup in templates directly), but I think that would be nice way of doing simple tubmlr-style blog.

  • Like 4

Share this post


Link to post
Share on other sites

Nice! It didn't know you can do that. We definately need a markup guide and templating guide with different approaches. There are some great posts hidden in this forum. If only I could find some time to collect all that information.

  • Like 3

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...