Topic: help for foreach wit if statement

It does not work help please

<?php $pages = Page::children('blog'); ?>
<ul class="list-unstyle">
<?php foreach($pages as $page) { ?>
if (strpos(<?php echo $page['title']; ?> ,'a';) !== false) {
    <li>tak</li>;
    }     
<?php } ?>
</ul>

2 (edited by gambi 2015-08-11 13:46:46)

Re: help for foreach wit if statement

Hi Legmet

you are getting confused as to what is php and what is html

<?php $pages = Page::children('blog'); ?>
<ul class="list-unstyle">
<?php 
    foreach($pages as $page) 
    {
        if (strpos($page['title'] ,'a') !== false) {
            echo '<li>tak</li>';
        }
    }    
?>
</ul>

I'm also not sure what you are trying to do but this could help you.

Re: help for foreach wit if statement

thx a lot it is working
i am trying to do small snippet for blog's post to find posts via title

Re: help for foreach wit if statement

<?php $pages = Page::children('blog'); ?>
<ul class="list-unstyle">
<?php 
    foreach($pages as $page) 
    {
        if (strpos($page['title'] ,'name') !== false) {
            echo '<li>';
            echo $page['title'];
            echo '</li>';
        }
    }    
?>
</ul>

above code sorts blog post titles via name value

Re: help for foreach wit if statement

if blog post's title contains string "name" it shows list with proper titles with links

<?php $pages = Page::children('blog'); ?>
<ul class="list-unstyle">
<?php 
    foreach($pages as $page) 
    {
        if (strpos($page['title'] ,'name') !== false) {
            echo '<li>';
            echo '<a href="blog/'.$page['slug'].'">' .$page['title']. '</a>';
            echo '</li>';
        }
    }    
?>
</ul>