ProcessWire - Snippets: Unterschied zwischen den Versionen
Aus Wikizone
(→Topnav) |
|||
| Zeile 1: | Zeile 1: | ||
== Navigation == | == Navigation == | ||
| + | === Redirect anderer Seite in der Navigation === | ||
| + | https://processwire.com/talk/topic/762-howto-menu-item-that-links-to-another-page/ | ||
| + | |||
| + | 1. Create a new field and call it 'redirect_url' or something like that, and use the 'URL' fieldtype. | ||
| + | |||
| + | 2. Add that field to your template where you'd want to use it, or create a new template just for the purpose, like a template named 'redirect'. | ||
| + | |||
| + | 3. Edit the page that you want to be a symlink and populate the 'redirect_url' field with the URL you want it to redirect to. | ||
| + | |||
| + | 4. In your nav-generation code that links to the pages, do something like this: | ||
| + | <syntaxhighlight lang="php"> | ||
| + | <?php | ||
| + | $url = $subpage->get("redirect_url|url"); // use redirect_url if there, otherwise use url | ||
| + | echo "<a href='$url'>{$subpage->title}</a>"; | ||
| + | </syntaxhighlight> | ||
| + | 5. You might also want to add this to your template that has the 'redirect_url' field: just in case there's anything linking to it directly. That way it'll send people to the right place either way: | ||
| + | |||
| + | <?php | ||
| + | if($page->redirect_url) $session->redirect($page->redirect_url); | ||
| + | |||
=== Breadcrumb === | === Breadcrumb === | ||
<pre> | <pre> | ||
Version vom 24. Februar 2017, 18:34 Uhr
https://processwire.com/talk/topic/762-howto-menu-item-that-links-to-another-page/
1. Create a new field and call it 'redirect_url' or something like that, and use the 'URL' fieldtype.
2. Add that field to your template where you'd want to use it, or create a new template just for the purpose, like a template named 'redirect'.
3. Edit the page that you want to be a symlink and populate the 'redirect_url' field with the URL you want it to redirect to.
4. In your nav-generation code that links to the pages, do something like this:
<?php
$url = $subpage->get("redirect_url|url"); // use redirect_url if there, otherwise use url
echo "<a href='$url'>{$subpage->title}</a>";
5. You might also want to add this to your template that has the 'redirect_url' field: just in case there's anything linking to it directly. That way it'll send people to the right place either way:
<?php if($page->redirect_url) $session->redirect($page->redirect_url);
Breadcrumb
<!-- breadcrumbs -->
<div class='breadcrumbs'><?php
// breadcrumbs are the current page's parents
foreach($page->parents() as $item) {
echo "<span><a href='$item->url'>$item->title</a></span> ";
}
// optionally output the current page as the last item
echo "<span>$page->title</span> ";
?></div>
Nur 1.Level
<ul class='topnav'><?php
// top navigation consists of homepage and its visible children
foreach($homepage->and($homepage->children) as $item) {
if($item->id == $page->rootParent->id) {
echo "<li class='current'>";
} else {
echo "<li>";
}
echo "<a href='$item->url'>$item->title</a></li>";
}
// output an "Edit" link if this page happens to be editable by the current user
if($page->editable()) echo "<li class='edit'><a href='$page->editUrl'>Edit</a></li>";
?></ul>
Searchbar
<!-- search form-->
<form class='search' action='<?php echo $pages->get('template=search')->url; ?>' method='get'>
<input type='text' name='q' placeholder='Search' value='<?php echo $sanitizer->entities($input->whitelist('q')); ?>' />
<button type='submit' name='submit'>Search</button>
</form>
Conditions
// If the page has children, then render navigation to them under the body.
// See the _func.php for the renderNav example function.
if($page->hasChildren) {
$content .= renderNav($page->children);
}
// if the rootParent (section) page has more than 1 child, then render
// section navigation in the sidebar
if($page->rootParent->hasChildren > 1) {
$sidebar = renderNavTree($page->rootParent, 3) . $page->sidebar;
}