Jump to content

Please, I need a little help with PHP


gfdesign
 Share

Recommended Posts

Hi. I want to use the MixItUp script where I put the names category as filter. Basically, I need to achieve this:

<script type="text/javascript">
    $(function(){
        $('#Grid').mixitup({
            multiFilter: true,
            showOnLoad: 'category_1 category_2 category_3 category_4 category_5'        
        });
    });
</script>
 

I use this code for getting the names category pages but, it adds an space at the first  (generated by echo " " in order to separate the categories) that doesn't let to work correctly.

<script type="text/javascript">
    $(function(){
        $('#Grid').mixitup({
            multiFilter: true,
            showOnLoad: '<?php $categories = $pages->get("template=categories")->children("template=categories, sort=sort"); foreach($categories as $category){echo " ".$category->name;}?>'        
        });
    });
</script>
 

With the above code I get this:

<script type="text/javascript">
    $(function(){
        $('#Grid').mixitup({
            multiFilter: true,
            showOnLoad: ' category_1 category_2 category_3 category_4 category_5'        
        });
    });
</script>
 

Could somebody help me to avoid adding an space at the beginning of the first category?
Thanks in advance
Fernando

Link to comment
Share on other sites

Thanks Arjen.

Finally, I used this code I found.

<?php
$resultstr = array();
$categorias = $pages->get("template=categorias")->children("template=categorias, sort=sort");
foreach ($categorias as $category) {
  $resultstr[] = $category->name;
}
$category = implode(" ",$resultstr);
?>

<script type="text/javascript">
    $(function(){
        $('#Grid').mixitup({
            multiFilter: true,
            showOnLoad: '<?php echo $category ?>'        
        });
    });
</script>
 

Surely, it can be optimized / improved, but it works
Thanks for your time

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...