aren Posted May 14, 2013 Posted May 14, 2013 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!
apeisa Posted May 14, 2013 Posted May 14, 2013 $allArticles = $pages->find("template=article|image|video|audio|quote, sort-=created, limit=20"); foreach($allArticles as $article) { echo $article->render(); } 2
aren Posted May 14, 2013 Author Posted May 14, 2013 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?
k07n Posted May 14, 2013 Posted May 14, 2013 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.
kongondo Posted May 14, 2013 Posted May 14, 2013 (edited) $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 May 14, 2013 by kongondo 1
apeisa Posted May 14, 2013 Posted May 14, 2013 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. 4
arjen Posted May 14, 2013 Posted May 14, 2013 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. 3
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now