Mijo Posted April 2, 2016 Share Posted April 2, 2016 I'm new in processwire, I must say it is great. I'm playing a little bit with some template, I have a little problem. How to display the latest posts on the home page? single.php contains blog posts On home page (home.php) I created children page with my blog post (example 1) My code looks like this: <?php foreach $pages->('template= home-single, limit=5'); ?> <div class='post'> <div class='content'> <h3>"<a href='{$single->url}'>{$single->title} </a>"</h3> </div> </div> <? endforeach; ?> Please Help, thank everyone Link to comment Share on other sites More sharing options...
diogo Posted April 2, 2016 Share Posted April 2, 2016 First of all, welcome to the forums! Hm, you have more than one problem in this line <?php foreach $pages->('template= home-single, limit=5'); ?> Try this instead: <?php foreach ( $pages->find('template=home-single, limit=5') as $single ); ?> Link to comment Share on other sites More sharing options...
horst Posted April 3, 2016 Share Posted April 3, 2016 Is the template name of your single blog posts really "home-single"? If not, you also have to change "home-single" in your pages->find selector to the real name of its template (in @diogos code example). Ah, - and welcome to the forums @Mijo. 1 Link to comment Share on other sites More sharing options...
SiNNuT Posted April 3, 2016 Share Posted April 3, 2016 Also, i think your foreach structure might be wrong. Link to comment Share on other sites More sharing options...
teppo Posted April 3, 2016 Share Posted April 3, 2016 Try this instead: <?php foreach ( $pages->find('template=home-single, limit=5') as $single ); ?> A minor correction to the above example: change the ";" at the end to ":" 2 Link to comment Share on other sites More sharing options...
Mijo Posted April 3, 2016 Author Share Posted April 3, 2016 (edited) Thank you all for your help I really appreciate it. It seems to me that everything is okay, there are no errors except title of blog post, I can not display the title blog post on the home page: Here is my code: <?php foreach ( $pages->find('template=single, limit=5') as $single ):?> <div class='post'> <div class='content'> <a href='{$single->url}'><h3>{$single->title}</h3> </a> </div> </div> <? endforeach; ?> Edited April 3, 2016 by kongondo Please wrap code in code blocks. See the <> icon just below the smiley Link to comment Share on other sites More sharing options...
diogo Posted April 3, 2016 Share Posted April 3, 2016 Oh, of course. When using this kind of foreach structure you have to reopen PHP to echo your object properties. You can open it with <?php or echo them with the shorter version <?= <?php foreach ( $pages->find('template=single, limit=5') as $single ):?> <div class='post'> <div class='content'> <a href='<?=$single->url?>'><h3><?=$single->title?></h3> </a> </div> </div> <? endforeach; ?> You can also use the most common PHP structure, where you don't go in and out of php. Your choice. Anyway, I think you would benefit a lot from studying the basics of PHP while using ProcessWire.It's not hard at all and will making everything more clear for you. 2 Link to comment Share on other sites More sharing options...
Mijo Posted April 3, 2016 Author Share Posted April 3, 2016 Oh, of course. When using this kind of foreach structure you have to reopen PHP to echo your object properties. You can open it with <?php or echo them with the shorter version <?= <?php foreach ( $pages->find('template=single, limit=5') as $single ):?> <div class='post'> <div class='content'> <a href='<?=$single->url?>'><h3><?=$single->title?></h3> </a> </div> </div> <? endforeach; ?> You can also use the most common PHP structure, where you don't go in and out of php. Your choice. Anyway, I think you would benefit a lot from studying the basics of PHP while using ProcessWire.It's not hard at all and will making everything more clear for you. Than you, it works Certainly I will dive in into php and Processwire. Thank you all for help 2 Link to comment Share on other sites More sharing options...
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