Jump to content

Category or tag wise listing of pages


peterpp
 Share

Recommended Posts

Hi,

  I want to list my projects categorywise like by which technology i used for projects. I am placing buttons for each technology. 

When i am clicking any button, i want to display all projects of that category. Single project can have multiple categories.

I have created Category page as parent and created child pages by technology names. I have used page field to select multiple categories to a project.

I am going wrong somewhere in writing code.  Plz help me with code.

Regards,

Pravin 

Link to comment
Share on other sites

I have used page field to select multiple categories to a project.

Make a template file for your categories. Inside that template file, the $page will be a category. Now you find all projects that have this category selected in the page field. Assuming the page field is called “cat” and the project template is “Project”:

$projects = $pages->find("template=Project, cat={$page}");

Link to comment
Share on other sites

Make a template file for your categories. Inside that template file, the $page will be a category. Now you find all projects that have this category selected in the page field. Assuming the page field is called “cat” and the project template is “Project”:

$projects = $pages->find("template=Project, cat={$page}");

Thanx Peter and Jan for  help. I will try this and let you know..Thanx a crore

Regards,

Pravin

Link to comment
Share on other sites

Hi,

     I am unable to explain detail requirement in last post. 

So, i am provoding structure below.

Clients(This is Parent page)

    - Client A  (This child page have tags/categories which are selected from page fields. eg. Processwire, Html, Css etc)

    - Client B  (This child page have tags/categories which are selected from page fields. eg. Processwire, Html, Css etc)

    - Client C  (This child page have tags/categories which are selected from page fields. eg. Processwire, Html, Css etc)

    --so on... (This child page have tags/categories which are selected from page fields. eg. Processwire, Html, Css etc)

Tags/Categories (This is Parent Page)

     -- Processwire (These are the tags/categories i am selecting from page field to assign to Clients)

     -- Html (These are the tags/categories i am selecting from page field to assign to Clients)

     -- Css (These are the tags/categories i am selecting from page field to assign to Clients)

     -- so on (These are the tags/categories i am selecting from page field to assign to Clients)

I want to display all clients on clients page bydefault and buttons for Tags/Categories.

Then,  when i click on any button, i want to display only that tags/categories pages.

Plz help me..

Regards,

Pravin

Link to comment
Share on other sites

@pravin,

you would have maybe 3 different options, the 1st 2 being server-side:

1.) Create a page called /tag/ or /category/ and then have it accept URL segments; then you would analyze the url segment and use that in a selector to get the pages to show.

/tag/css/ (where css is the segment), and then you would use $input->urlSegment1 to tell which pages to get.

2.) use a URL with a querystring, like this: mysite.com/?category=css

then use $input->get to build your selector.

3.) have category page that lists all the projects and have filters for category and tag, using e.g. isotope.

Link to comment
Share on other sites

If you want to filter content while staying on the same page, you’ll have to use Javascript. Peter posted a good approach you can use. Here is another jQuery library that can do what you want: https://mixitup.kunkalabs.com/. If you know a bit of Javascript/jQuery, it shouldn’t be too hard to build yourself, either.

Basically, the idea is to tag your content with a class and then filter by that. For example:

$clients = $page->children();

echo '<ul>';
foreach ($clients as $client) {
    //This creates a string of category-IDs. If this client has 3 categories, it may look like "1099 1350 9001".
    $classes = $client->categories->implode(' ', 'id');

    echo "<li class='{$classes}'>{$client->title}</li>";
}
echo '</ul>';

So now you have a list of clients that each belong to some classes. You make a couple of links or buttons to filter by these classes. We recognize the items by the page-ID that is in their classes, but we have to tell the button which ID it should filter, so we put the ID in the id tag.

$categories = $pages->find('parent=/categories/');

foreach ($categories as $cat) {
    echo "<a href='#' id='{$cat->id}' class='filterbutton'>{$cat->title}</a>";
}

You use jQuery to remove all elements that don’t belong to the selected class:

<script type="text/javascript">
    $(document).ready(function(){
        //When one of the buttons was clicked, run the function 
        $('.filterbutton').click(filter);

        function filter(event) {
            //First, hide everything.
            $('li').hide();

            //Get class you want to show from the button’s id attribute
            var class = $(this).attr('id');

            //Show all items that have this class
            $('li.' + class).show();
        }
    }
</script>

This is pretty crude and not guaranteed to work or work correctly. Just use it as a base to build from.

  • Like 2
Link to comment
Share on other sites

Thanx for solutions. What i am thinking is i will display child pages based on field value. i.e when i click Processwire button, all child pages that have pagefiled value "Processwire". Is it possible and best way to achieve this functionality?

Regards,

Pravin

Link to comment
Share on other sites

Hi all,

   I did it as i described in last post..

<?php 
                    $posts = $pages->find("page_select=Processwire");
                      echo "<ul>";
                           foreach ($posts as $k) {
                                 echo "<li>$k->title</li>";
                              }
                        echo "</ul>";
 ?>
 
where page_select is pagefiled type. 
 
 
Thanx for everybody's help..
 
Regards,
Pravin
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

  • Recently Browsing   0 members

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