spamec Posted January 17, 2012 Share Posted January 17, 2012 Hi, I'm developing my first site with PW. Got it brilliant idea, but head cant get around old thinking My problem: I have to make a list of news categories with links to news-list template with specific category (to filter news out). Category list: <?php $newsIndex = $page->find('template=news-list'); ?> <?php $categories = $pages->get('template=news-categories')->children;?> <?php foreach($categories as $c): ?> <?php echo "<li><a href='{$newsList->url}{$c->path}'>{$c->title}</a></li>"; ?> <?php endforeach;?> Filtering news: $selectedCategory = ''; $news = $page->children("category={$selectedCategory}, sort=-date"); Question: How to create url to $newsList page with category as parameter? How to get parameter from url and then filter news out? Maybe, there's any section in API covering this topic (I didnt found it) Link to comment Share on other sites More sharing options...
apeisa Posted January 17, 2012 Share Posted January 17, 2012 Hi spamec and welcome to the forums! You are looking for $input->urlSegments(n): http://processwire.com/api/variables/input/ Of course you can use get-variables also, and access them from $input->get('parametername') Urls you have almost right, just change {$c->path} => {$c->name} 1 Link to comment Share on other sites More sharing options...
spamec Posted January 17, 2012 Author Share Posted January 17, 2012 Thanks apeisa for support, creating url is working (was really close), but I'm facing new problem. My structure: /news - news-list /story/news-name - news entry /news/category-name - which is the case, now when I enter this url I get 404, which is true as page with category-name doesnt exists... I used to work with MVC pattern, so this is new situation for me (sorry for stupid questions) Link to comment Share on other sites More sharing options...
apeisa Posted January 17, 2012 Share Posted January 17, 2012 Ah, you just need to edit your news template settings, urls tab and allow url segments. 1 Link to comment Share on other sites More sharing options...
spamec Posted January 17, 2012 Author Share Posted January 17, 2012 Damm, you thought about everything Thanks once again Link to comment Share on other sites More sharing options...
apeisa Posted January 17, 2012 Share Posted January 17, 2012 Not me, Ryan did Link to comment Share on other sites More sharing options...
Badriansyah Posted June 14, 2017 Share Posted June 14, 2017 i just got a same problem and solved thank you both 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now