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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By jds43
      Hello, I'm trying to list the categories, on the front through select options, that have been selected by page reference field (multiple pages PageArray) on the child pages.
      Things to Do (would only display three, six, seven, nine in select)
      -thing one (-category three, -category nine)
      -thing two (-category six, -category seven)

      Lodging (would only display one, two, three, four in select)
      -lodging one (-category one, -category two)
      -lodging two (-category three, -category four)

      Dining (would only display five, six, seven, eight in select)
      -dining one (-category five, -category six)
      -dining two (-category seven, -category eight)
      Categories(hidden page)
      -category one
      -category two
      -category there
      -category four
      -category five
      -category six
      -category seven
      -category eight
      -category nine
      -category ten
      $categories = $pages->find(1129)->children('include=hidden'); foreach($categories->references('category') as $ref) { echo $ref->title; } This selector isn't working, but it seems 'references' would be helpful. I've never used it before, so I'm not sure how to employ for this.
      https://processwire.com/blog/posts/processwire-3.0.107-core-updates/#page-gt-references
    • By stanoliver
      Good morning everyone!
      I have a growing number of posts about cars, bikes, airplanes, etc. 
      The following code (below) just works fine and returns only the posts of the category=cars as I desired together with pagination.
      In my url I have for example /categories/cars/car1 or /categories/bikes/bike1
      I do want to filter my posts not only with ... category=cars ... but also with category=bikes or category=airplanes and at best:
      If my url is /categories/bikes/ then ... category=cars ... should be overwritten or replaced by ... category=bikes ... 
      If my url is /categories/airplanes/ ... then the filter should be ... category=airplanes ... (I know a work around by creating almost identical templates where I could just change the "category=cars" part of my code but that's comes of a prize by repeating a lot of identical code and is not a good habit). In the documentation I read something about the "has_parent" selector but I could not get to work it related to the urls mentioned above.
      <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=cars, limit=5, sort=-postdate') as $post 😞?> <!-- Blog entry --> <div class="g8-card-4 g8-margin g8-white"> <!--<img src="/g8images/bridge.jpg" alt="Norway" style="width:100%">--> <div class="g8-container"> <h3><b><?= $post->title; ?></b></h3> <h5>Datum: <span class="g8-opacity"><?= $post->postdate; ?></span></h5> </div>   <div class="g8-container"> <p><?= $post->posteditor; ?></p> <div class="g8-row"> <div class="g8-col m8 s12"> <p> <a href="<?= $post->url; ?>"><button class="g8-button g8-padding-large g8-white g8-border"><b>Details lesen &raquo;</b></button></a> </p> </div> <div class="g8-col m4 g8-hide-small"> <!--<p><span class="g8-padding-large g8-right"><b>Comments &nbsp;</b> <span class="g8-badge">2</span></span></p>--> </div> </div> </div> </div> <!-- END BLOG ENTRIES --> <?php endforeach; ?>   <? echo $results->renderPager(array( 'nextItemLabel' => "rückwärts", 'previousItemLabel' => "vorwärts")); ?>
    • By adrian_gp
      Hello everyone,
      I'm new in this forum and my english is not perfect so sorry for the mistakes.
      I have an Blog Project and i will use categories. 
      Here is the structure:
      Blog -> displays all the Blogposts (template=BlogPage) Post-Name -> display the specific Post (template=BlogPost) Categories -> not visible in the menu (template=CategoriesPage) Categorie-Name -> not visible in the menu (template=CategoriePage) For your information:
      (BlogPost) every blogpost has its own page (BlogPost) in Admin i can select the categorie per Field -> SelectMultiple Pages (Checkbox) (fieldname=categories) (Blog) displays all the BlogPosts and all the categories under the ParentTemplate CategoriesPage, which also have their own side Now the Problem:
      On Blog -> I would like to click on a category and only see the post that has this category checked in the BlogPost.
      CategoriePage -> what do I have to insert there to show only the specific posts which use the checked categorie?

      Let me know if you need more information

      Thanks for your support
       
    • By zaib
      I've a page "blog" which have child pages (blog posts). Right now I've 11 pages (blog posts) and I'm fetching all the posts in my "blog" pages which displaying fine, Issue is only 10 results are showing this is how I'm fetching
      $entries = $pages->find("template=blog-entry"); foreach($entries as $entry){ <a href='{$entry->url}'>$entry->title</a> }  
    • By Outcydaz
      I have a site structure as follows
      Shirts
      -- Shirt One
      -- Shirt Two
      Shoes
      -- Shoe One
      -- Shoe Two
      Category
      -- Spring Summer
      -- Fall Winter
      Each page has a 'category' page field.
      I'm trying create a navigation that shows only the child categories as follows:
      Shirts
      -- Spring Summer
      -- Fall Winter
      Shoes
      -- Spring Summer 
      -- Fall Winter
      When Shirts -> Spring Summer is clicked i'd see only spring summer shirts. Same for Shoes, you'd only see Spring summer items for shoes.
      Help please.
       
×
×
  • Create New...