Jump to content

Categories not visible. Incorrect setup?


FrancisChung
 Share

Recommended Posts

Hi there,

I've setup Categories as an unpublished page with child pages with basic-page as the template.

I think this was the recommended setup as per several forum postings.

Home/Categories

Home/Categories/Category1

Home/Categories/Category2

   

I've just found out that I can't get a list of the Categories or the pages via the Pages object.

$pages->get("/Categories") yields nothing

If I change the visibility to unpublished to hidden, I can see the pages but then I have a problem where the /Categories URL becomes accessible. 

Is there a way to get around this?

I'm new to Processwire & Web Development in general so apologies if this is a trivial question

 
Link to comment
Share on other sites

Often those accessable url's are used for the pages only showing a specific category, but you can surely prevent that.

  • One way would be using only templates without a corresponding template.php file. If there's no file, then there's nothing to render, which results in the default 404 error.
  • Another way would be using the right selector to get the categories $pages->find("parent.id=[path=/categories, include=unpublished]"). This does get you all children of the page found by the selector within the square brackets (subselector). Keep in mind, that urls are always lowercase.
  • Like 2
Link to comment
Share on other sites

The second method works for me.

Danke LostKobrakai for the quick reply!

Often those accessable url's are used for the pages only showing a specific category, but you can surely prevent that.

  • One way would be using only templates without a corresponding template.php file. If there's no file, then there's nothing to render, which results in the default 404 error.
  • Another way would be using the right selector to get the categories $pages->find("parent.id=[path=/categories, include=unpublished]"). This does get you all children of the page found by the selector within the square brackets (subselector). Keep in mind, that urls are always lowercase.
Link to comment
Share on other sites

Hello how do you add php into an unordered list like below ? 

<?php // Render the Category List
 categoriesList(); ?>
<?php 

into 

<ul  class="oi_smalldev_categories_list">
    <li class="cat-item cat-item-7">
        <a href="category/coding/index.html" title="This extended category features articles on client-side and server-side programming languages, tools, frameworks and libraries, as well as back-end issues. Experts and professionals reveal their coding tips, tricks and ideas.">Coding</a>
    </ul>

Thank you.

Link to comment
Share on other sites

your categoriesList() function would need to echo the desired markup.

that function will be completely dependent on your page tree structure, as well as what if any arguments you will allow to pass into the function.

Link to comment
Share on other sites

i don't see any benefit to using a function, you could just output the list in the normal way:

<ul class="oi_smalldev_categories_list">

<?php
    $count = 1;
    foreach($categories as $category) {
        echo "<li class='cat-item cat-item-{$count}'>";
        echo "<a href='{$category->url}' title='{$category->summary}'>{$category->title}</a>";
        echo '</li>';
        $count++;
    }
?>

</ul>
  • Like 1
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...