• Resolved MyWorldz

    (@myworldz)


    Hi there,

    1) Is it possible to have a different template for each category?

    2) Where can I find the files with the divs below?
    div.cn-list-body AND div.cn-list-row cn-list-item vcard

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Steven

    (@shazahm1hotmailcom)

    RE: 1) Is it possible to have a different template for each category?

    It is not a setup I would recommend, but you could create a directory page for each category and use the category and template shortcodes to define the category and template that should be displayed.

    RE: Where can I find the files with the divs below?

    They can be found in the class.template-parts.php file:

    The class names can be changed using these filters:

    • cn_list_body_class
    • cn_list_row_class

    I hope this helps; please let me know.

    Thread Starter MyWorldz

    (@myworldz)

    Thank you for your reply.

    RE: 1) Is it possible to use a different template for each category?

    Sorry, I may be misunderstanding. So just to clarify a bit. Say for example, I created a category for “employees” and one for “contractors” but I need a different layout for each of those categories. Can I copy the card.php and card-single.php and assign them to match the category, eg:

    card-employees.php
    card-single-employees.php

    card-contractors.php
    card-single-contractors.php

    Thanks!

    • This reply was modified 2 years, 1 month ago by MyWorldz.
    Plugin Author Steven

    (@shazahm1hotmailcom)

    RE: Can I copy the card.php and card-single.php and assign them to match the category

    Yes, you can, but those templates will load when being queried by the category. Ex:

    • your-site.com/directory-homepage/?cn-cat=1
    • your-site.com/directory-homepage/?cn-cat=1

    Or…

    • your-site.com/directory-homepage/cat/contractors
    • your-site.com/directory-homepage/cat/employees

    The 1 and 2 would be the category ID numbers for “employees” and “contractors” found on the Connections Categories admin page. Or the permalinks for those categories.

    If you wish to have different layouts based on category but not have to query by category, you can use code to load your custom template, similar to how I described to this other user:

    You would use something like this to load your custom layouts in the card.php file:

    <?PHP
    
    $categories = array();
    
    foreach ( $entry->getCategory() as $category ) {
    	$categories[] = $category->slug;
    }
    
    if ( in_array( 'contractors', $categories ) ) {
    	include 'contractors.php';
    } elseif ( in_array( 'employees', $categories ) ) {
    	include 'employees.php';
    } else {
    	include 'original.php';
    }
    

    I hope this helps; please let me know.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multiple Templates and Looking For Files’ is closed to new replies.