Here is the line of code I use to display a page’s unique ID.
<?php echo $c->getCollectionID() ?>
This is really useful for styling individual pages.
Here is the line of code I use to display a page’s unique ID.
<?php echo $c->getCollectionID() ?>
This is really useful for styling individual pages.
Here is how I exclude specific page types from an autonav menu in Concrete5.
Navigate to concrete/blocks/autonav and open the view.php file.
Scroll down to this line:
foreach($aBlocks as $ni) {
$_c = $ni->getCollectionObject();
if (!$_c->getCollectionAttributeValue('exclude_nav')) {
Add this block of code:
$typeHandle = $_c->getCollectionTypeHandle();
if($typeHandle!="page_type"){
Change “page_type” to the handle of page type that you want to exclude from your autonav menu (for example: blog_post).
Now scroll down and add “}” after this line:
$lastLevel = $thisLevel; $i++;
You can also see or download the edited view.php here (this is a text file, so if you want to use it, make sure you save it as a php file!!).
Here is one way I have found to fix an issue in Concrete5 where your captcha images are not showing up.
Navigate to concrete/helpers/validation/ on your server and open captcha.php.
Find this block of code:
class ValidationCaptchaHelper {
private $securimage;
public function __construct() {
Loader::library("3rdparty/securimage/securimage");
$this->securimage = new Securimage();
$this->securimage->ttf_file = DIR_LIBRARIES_3RDPARTY_CORE . '/securimage/elephant.ttf';
}
And change it to:
class ValidationCaptchaHelper {
private $securimage;
public function __construct() {
Loader::library("3rdparty/securimage/securimage");
$this->securimage = new Securimage();
$this->securimage->use_gd_font = true; $this->securimage->gd_font_file = DIR_LIBRARIES_3RDPARTY_CORE.'/securimage/gdfonts/caveman.gdf';
$this->securimage->ttf_file = DIR_LIBRARIES_3RDPARTY_CORE . '/securimage/elephant.ttf';
}
The text in red is the text that you are adding to the original block of code.
This worked for me but let me know if it doesn’t work for you.
Here is the easiest way I have found to add a unique body class to individual pages in a Concrete5 site.
First, in your dashboard go to “Pages and Themes,”then “Attributes,” and add a custom attribute (text field) called bodyclass.
Next, open your theme’s header.php file and add:
class="<?php echo $c->getCollectionAttributeValue('bodyclass')?>"
to your < body > tag, so it reads like this:
<body class="<?php echo $c->getCollectionAttributeValue('bodyclass')?>">
For any page that you want to apply a custom class to, simply add the Body Class custom attribute and type whatever class name you want into the Body Class Custom Attribute text field. When you save your changes, your opening < body > tag will now look like:
<body class="red">
First, copy and paste this code into a blank text file:
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$aBlocks = $controller->generateNav();
$c = Page::getCurrentPage();
echo("<ul class=\"nav\">");
$nh = Loader::helper('navigation');
$isFirst = true;
foreach($aBlocks as $ni) {
$_c = $ni->getCollectionObject();
if (!$_c->getCollectionAttributeValue('exclude_nav')) {
$target = $ni->getTarget();
if ($target != '') {
$target = 'target="' . $target . '"';
}
if ($ni->isActive($c) || strpos($c->getCollectionPath(), $_c->getCollectionPath()) === 0) {
$navSelected='nav-selected';
} else {
$navSelected = '';
}
$pageLink = false;
if ($_c->getCollectionAttributeValue('replace_link_with_first_in_nav')) {
$subPage = $_c->getFirstChild();
if ($subPage instanceof Page) {
$pageLink = $nh->getLinkToCollection($subPage);
}
}
if (!$pageLink) {
$pageLink = $ni->getURL();
}
if ($isFirst) $isFirstClass = 'first';
else $isFirstClass = '';
echo '<li id="'.$navSelected.'" class="item'.$_c->getCollectionID().' '.$isFirstClass.'">';
if ($c->getCollectionID() == $_c->getCollectionID()) {
echo('<a class="nav-selected" href="' . $pageLink . '" ' . $target . '>' . $ni->getName() . '</a>');
} else {
echo('<a href="' . $pageLink . '" ' . $target . '>' . $ni->getName() . '</a>');
}
echo('</li>');
$isFirst = false;
}
}
echo('</ul>');
Save this file as new-nav.php or whatever you want it to be called. Upload this template to your concrete/blocks/autonav/templates.
Now, in your template file, use this block of code to call the new menu:
<?php
$nav = BlockType::getByHandle('autonav');
$nav->controller->displayPages = 'top';
$nav->controller->orderBy = 'display_asc';
$nav->controller->displaySubPages = 'all';
$nav->render('templates/new_nav');
Note: make sure that you use the correct name of your new template in the code above.
Or, if you are adding or editing an autonav block from the front end of the site, simply select the “New nav” custom template and apply it to the block.
Let me know if you run into any questions or have any issues with this.