Passing category from perch admin into perch_blog_custom

  • I need to add the most recent 5 blog post titles on dynamically created perch pages using a category that is chosen in perch admin.


    In the master page, I can choose the Blog Category for the page using the following html template which allows me to chose which category I want from a drop down. Here I can get the category link.


    <perch:before><ul></perch:before> <li> <perch:categories id="category" set="blog" label="Category"> <a href="blog/archive.php?cat=<perch:category id="catSlug" type="slug" />"> <perch:category id="catTitle" /> </a> </perch:categories> </li> <perch:after></ul></perch:after>


    But what I really want is a list of blog titles based on that category ie. use perch_blog_custom(). How do I pass the category I have chosen via perch admin, into perch_blog_custom?


    <?php

    perch_blog_custom([

    'sort'=>'postDateTime',

    'sort-order'=>'DESC',

    'template'=>'blog/post_title_in_list.html',

    'category' => ??????

    'count'=>5

    ]);

    ?>

  • drewm

    Approved the thread.
  • Hi Hussein. Yes - I was going to do it by passing the category into perch_blog_custom() so I could take advantage of the sort, count etc, but I couldn't work out how to pass in the category that I've obtained from the content region. But yes - filtering the blog by a category is essentially what I'm wanting to do.

  • You can get back the data from the content region using perch_content_custom() with the skip-template option.


    This will give you your data as an array, and you can get the category from that array and use it in the blog options.