Move content or organize content to a other category in the main nav

Hello,

im working on a award page and wanna use Kirby as CMS, so iam not really sure how i can fix the following synerio:

  • The Navigation: judge - winner - nominees

Every Nominee has a own lading page, so when the nominated project
become a winner project, how i can move or organize the page to the winner sites?

Any help or thoughts on this?

The question is if you really have to move pages. Wouldn’t it work if you had a select or radio field with these categories, and then filter pages by the value of this field?

yes, i think on that too. How i would grab the content from a other main folder?

  • so i have a winner and a nominees folder right?

Yes, you can have a nominees and a winner folder. All subfolders would be in the nominee parent. The winner folder would be empty.

Then two templates.

<?php
// nominee.php
$nominees = $page->children()->filterBy('status', 'nominee');
<?php
// winner.php
$winners = page('nominees')->children()->filterBy('status', 'winner');
1 Like

How i can set the status in my blueprint? - i have created a checkbox like this:

winner:
label: Winner
type: checkbox
text: add it to the Winner Page

Is this right? Not sure how to define the status

Yes, you can do it like that.

If you use a checkbox and the checkbox is checked, Kirby will add a “1” in the content file. You can then filter these pages like this:

$winners = page('nominees')->children()->filterBy('winner', '1');
1 Like

2 posts were split to a new topic: How to get a specific image by filename

2 posts were split to a new topic: How to get the first or last 2 items in a collection

The filter works fine. Now the problem is, that when iam clicking on a winner project,
the Nav high lighting “Nominees”

How i can make it possible that winner projects will activate right in the nav?

Could you post your navigation code please?

<div id="navbar" class="collapse navbar-collapse">
	<ul class="nav navbar-right navbar-nav">
    <?php foreach($pages->visible() as $p): ?>
     	<li<?php e($p->isOpen(), ' class="active"') ?>>
			<a href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
		</li>
    <?php endforeach ?>
		<li><a href="submit"><button type="submit" class="btn btn-default btn_pt">submit</button></a></li>
	</ul>
</div>

i could´t paste the script so here is shot

What happens when you click on an item? Does the url still show ‘nominees’ for a winner?

The URL still show “nominees” all projects are in this folder

I think the first thing you should do is create a custom page method to change the url if the page is a winner:

<?php
page::$methods['specialUrl'] = function($page) {
    return site()->url() . '/winners/' . $page->uid();
};

In your winners template, you can then use this page method:

<?php 
$winners = page('nominees')->children()->visible()->filterBy('winner', '1');

foreach($winners as $winner): ?>
  <a href="<?= $winner->specialUrl() ?>">Go to winner</a>
<?php endforeach ?>

Then you need a route to prevent getting the error page at the new url:

c::set('routes', array(
  array(
    'pattern' => 'winners/(:any)',
    'action'  => function($uid) {
      $page = page('nominees/' . $uid);
      if($page) {
        return $page;
      } else go('error');
    }
  )
));

With this route, the winners can be reached with a URL like this: http://example.com/winners/winner-one

Navigation:

<nav class="navigation column" role="navigation">
  <ul class="menu">
    <?php foreach($pages->visible() as $item): ?>
    <li class="menu-item<?= r($item->isOpen() || ($item->uid() == 'winners' && $page->winner() == '1'), ' is-active') ?>">
      <a href="<?= $item->url() ?>"><?= $item->title()->html() ?></a>
    </li>
    <?php endforeach ?>
  </ul>
</nav>

Thank you for this, i will try it out. So first to get you right:

the first code block i have to create a snippet file?

Where have to put the C:SET … code?

The page method goes into a file in /site/plugins , I usually have a file methods.php where I put such stuff.

The c::set()command you can put into your config.php.

I get an error when is use it like this in my Menu Snippet:

<div id="navbar" class="collapse navbar-collapse">
	<ul class="nav navbar-right navbar-nav">
    <?php foreach($pages->visible() as $p): ?>
     	<li<?php e($p->isOpen() || ($p->uid() == 'winners' && $page->winner() == '1'),  ' class="active"') ?>>
			<a href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
		</li>
    <?php endforeach ?>
		<li><a href="submit"><button type="submit" class="btn btn-default btn_pt">submit</button></a></li>
	</ul>
</div>

What sort of error?

(And could you please wrap code blocks within three backticks on a separate line before and after the block? Thank you!
You can click on the edit button to see how it should look)

Maybe your page or the field are named differently?

Yes, always searched for generating cod blocks here, now i know. I get this Error:

This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible.