Jump to content

Categorization through UrlSegments problem


daniel.s
 Share

Recommended Posts

Hello!

I've hit a wall with UrlSegments.

I've created a select field in the children pages with http://modules.processwire.com/modules/fieldtype-select/  named "category" with 3 options; news, pressreleases, articles.

I read through this topic and tried to somewhat duplicate the process:

http://processwire.com/talk/topic/4716-returning-articles-with-the-same-article-date-category-and-tags/?hl=filtering#entry46196

when i try going to the page ex. my.page.com/news/articles with "articles" as the key for the "category" field i get this message:

Error: Exception: Unknown column 'field_category.name' in 'on clause' (in /Applications/MAMP/htdocs/processwire/wire/core/Database.php line 118)

Here's my code:
 

        <section class="newsList last">
            
            <?php if ($input->urlSegment1) {
                $results = $pages->find("parent=$page, limit=10, category.name=$input->urlSegment1, sort=-date");
            
            } else {
                $results = $pages->find("parent=$page, limit=10, sort=-date");
            } 

				$pagination = $results->renderPager();
				foreach($results as $news) { 
			?>
                <article>
                    <h2><a href="<?php echo $news->url; ?>"><?php echo $news->get("headline|title"); ?></a></h2>
                    <small>
                        <time>
                            <?php 
                                $datefield = $news->get("date|created");
                                echo date("F, Y", $datefield); 
                            ?>
                        </time>
                    </small>
                    <p><?php echo $news->summary; ?>
                    <?php echo wordLimiter($news->summary. $news->body); ?></p>
                    <p><a href="<?php echo $news->url; ?>">Read more ››</a></p>
                </article>
            <?php } ?>
            
            <?php echo $pagination; ?>
        
        </section>

What am i doing wrong? Read through all related topic but can't seem to find the problem

Link to comment
Share on other sites

What version of PW? Are you sure that category is a field of type "Page" ? Does it work if you change it to this?

if($input->urlSegment1) {
  $name = $sanitizer->pageName($input->urlSegment1); // remember to sanitize
  $category = $pages->get("template=category, name=$name"); 
  $results = $pages->find("parent=$page, limit=10, category=$category, sort=-date");
}

Also, just want to double check that you intend for the parent to be $page in that selector? That would mean your articles and category URL segments are sharing the same namespace. That's perfectly fine, but not that common to do that, so just double checking. 

Link to comment
Share on other sites

I only use the one template for this (news.php)

Dont know if it's the right way, or even possible to do this:

Want the template news to work for "mysite.com/news" but also for "mysite.com/news/category". So the if statement sais if i have a urlsegment (category), take the category name and get all children to "news" with a field called "category" that matches the url segment. If there's no urlsegment it gets all the children.

My goal is to have a flat news list without categories as parents but still be able to tag or categorize them through a field. Is there a better way?

Thanks!

Link to comment
Share on other sites

Got it working with a variation of your code:

if($input->urlSegment1) {
  $name = $sanitizer->pageName($input->urlSegment1); // remember to sanitize
  $results = $pages->find("parent=$page, limit=10, category=$name, sort=-date");
}

Thanks for all the help Ryan! I really appreciate it. Processwire is truly amazing. The more i learn about it and work in it the more i'm bummed about not finding it sooner!

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...