Jump to content

Recommended Posts

Posted
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
Posted

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 ); ?>
Posted

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. :)

  • Like 1
Posted

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 ":" :)

  • Like 2
Posted (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 by kongondo
Please wrap code in code blocks. See the <> icon just below the smiley
Posted

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.

  • Like 2
Posted

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 :-)

  • Like 2

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...