How to implement more complex navigation in PyroCMS? - php

I am new to PyroCMS 2.1 - I am creating a new template and wondering how to implement the following navigation - can it be done in PyroCMS at all?
<ul id="navlist">
<li id="nav_one"><a id="link_one" href="#">Item 1</a></li>
<li id="nav_two"><a id="link_two" href="#">Item 2</a></li>
...
</ul>
Basically, I need a different set of ID's for each menu item (li and a elements).
Advanced navigation tag options doesn't help: http://docs.pyrocms.com/2.1/manual/index.php/modules-and-tags/tag-reference/navigation.
Thanks!

Doesn't look like there is a native way to do this in PyroCMS, but you can add a class to each li in the navigation section of the admin panel.
If you do decide you really need the id's generated in your templates, you could look at extending the navigation module and widget yourself. You could update the database to include the fields you need, update the navigation module controller and models (and admin panel views) and update the widget to include the fields in the navigation variable.
Good luck!

Why are you guys hacking the core?!
You can do what you like with the Navigation HTML output but using the Tag Pair syntax.
Gotta love those double tags.

/system/cms/modules/navigation/plugin.php
attributes of anchor
$item['url'] `enter code here`= $link['url'];
$item['title'] = $link['title'];
$item['id'] = str_replace(' ','-',strtolower($link['title']));
I add this lastnew line and search this code line 198 aprox and
add (id="' . $item['id'] . ')
$output .= $ident_b . '<' . $tag . ($classes > '' ? ' class="' . $classes . '" id="' . $item['id'] . '">' : '>') . PHP_EOL;
before you can use that ...... (in the menu vavigations)
and you css make e.g. if name link is New Products you use css .new-products{......}

Related

issue in breadcrumbs of a custom taxonomy

I have a custom post type and custom taxonomies. Hierarchy of the pages is like this that first listing page is displayed. In listing page categories are also displayed.
If user is on listing page breadcrumbs is like this. Home/Projects and it is proper and working fine.
If user clicks on some category than breadcrumb is like this . Home/Project/category-1 . I also works fine.
ERROR:
If user clicks on any project than breadcrumb and its links are not proper.
Home/Projects/Projects-Catcategory-1/Al Murabit and its link is also like this.
code
$ref1 = parse_url(wp_get_referer());
if($taxonomy_names[0] )//||is_term()||is_singular())
{
echo '<li>' . $post_type->labels->singular_name . '6</li>';
if(str_replace('/','',str_replace($taxonomy_names[0],'',$ref1['path'])))
{
echo '<li><a href="' . $homeLink . '/' . $taxonomy_names[0] . '/'.
str_replace('/','',str_replace($taxonomy_names[0],'',$ref1['path'])).'">' .
str_replace('/','',str_replace($taxonomy_names[0],'',$ref1['path'])) . '30</a></li>';
}
}

Get Next/Previous (Sibling) Top Level Parent Page Id - Wordpress

Question: Is there any possibility to get next/previous page id in wp_nav_menu in wordpress.
Example: I have navigation menu like this
Menu_Item_1 (ID = 5)
>SubMenu_Item_1-1
>SubMenu_Item_1-2
Menu_Item_2 (ID = 11)
>SubMenu_Item_2-1
>SubMenu_Item_2-2
If I am on the Menu_Item_1 or any of its child pages, the id of the next top level menu item ( Menu_Item_2 in this case) must be stored in a variable and so on.
You can create a custom walker to achieve this. Here is a detailed explanation about it.
OR
Also, here is a possible workaround:
Edit nav-menu-template.php file which is under wp-includes folder.
Scroll down to line no. 114 which looks like:
$output .= $indent . '<li' . $id . $value . $class_names .'>';
replace this line with:
$output .= $indent . '<li' . $id . $value . $class_names .' data-id='. $item->object_id .'>';
This will add the original id's in all the <li> and will look like:
<li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-29" data-id="14">
Here data-id is having the id that you required. You can use jQuery to get this id:
targetId = $('#menu-item-29').attr('data-id');
Note: these changes would be overridden once you update your Wordpress installation.

How to list values of one php file in another php file

I am not sure if this is possible !
I have two files say main.php and submenu.php
In main.php i have the following mainMenu
and in another file called submenu.php i have a list say
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
If i click on Pricelist in main menu i want to display the content of the submenu as a list under PriceList as
The simple solution may be including the list view in menu.php itself, But that's not the situation
Thank you.
You should use arrays and recursion. Like so:
(code is rough, sorry)
$menu = array(
'About Us',
'Categories',
'Price List' => array(
'1','2','3','4'
)
);
function loop_menu($menu){
foreach($menu as $m):
if(is_array($m))
return '<ul>' . loop_menu($m) . '</ul>';
else
return '<li>' . $m . '</li>';
endforeach;
}
echo loop_menu($menu);
Then use CSS to make it look however your want.
If you want to include a page just use
include('page.php');
But using JS & CSS is the best way
Here is a very helpful plugin
http://users.tpg.com.au/j_birch/plugins/superfish/
And don't forget to get jQuery

Using HTML within Wordpress' Category name field

I need to add HTML to the Category names within my Wordpress theme, so that I can define the name as an icon (via the Twitter bootstrap).
Example code as follows:
<a href="link">
<i class="icon-briefcase"></i>
</a>
This would present the Category name as a linked icon.
Is there any way to do this. I've searched endlessly and the only Wordpress plugins I can find allow HTML to be added to the Category description only.
Thanks in advance.
I think what you're trying to do you can easily solve like this:
<?php
foreach((get_the_category()) as $category) {
echo '<a href="link">';
echo '<i class="icon-briefcase">' . $category->cat_name . '</i>';
echo '</a>';
}
?>
This will make all the category names appear like linked icons, like you said. If you want each name to have a different icon you can of course add a conditional statement to render different HTML based on the category name or ID.
EDIT:
Because you want to use the Twitter Bootstrap, you need to assign css classes to the links in order to the display the icon. There are two ways you can do this. One of 'em being that you could name your categories the same as the icons. For example, a category named 'briefcase', would render a link with the class 'icon-briefcase'. The code:
<?php
// Iterate through the available categories
foreach((get_the_category()) as $category) {
echo '<a href="link">'; // Display a link
echo '<i class="icon-' . $category->cat_name . '">' . $category->cat_name . '</i>'; // Create the <li>
echo '</a>';
}
?>
The second way, and I think a bit better for content purposes (more freedom for choice of cat names), would be to use a conditional statement in the code to assign icons to certain categories. For example:
<?php
// Iterate through the available categories
foreach((get_the_category()) as $category) {
// First define a default css name class to use
$iconclass = 'icon-default';
// Then using an if statement, assign a new css class name to the variable based on the name of the category
if($category->cat_name == 'Travel') { $iconclass = 'icon-briefcase'; }
echo '<a href="link">'; // Display a link
echo '<i class="'. $iconclass . '">' . $category->cat_name . '</i>'; // Create the <li>
echo '</a>';
}
?>
I hope this is clear enough.
I think what you want is just the Category Icons plugin.
I just had a similar kind of requirement to add a big capital letter at the beginning on some category names, (but not others) in the same list. The easiest way I found of doing this was using CSS. This is what I ended up doing
#projects-term-4 h5 a:before {
content:'H';
font-size:80px;
display:block;
margin-bottom:10px;
color:white;
}
#projects-term-5 h5 a:before {
content:'S';
font-size:80px;
display:block;
margin-bottom:10px;
color:white;
}
... etc
You could probably impliment a very simple workaround using this method without knowing any php coding or installing any extra plugins. you'll just need to inspect the html code of the generated page to get the class names and id's you need.

Magento static pages menu

I want to make a menu that will dynamically show the active static pages from CMS; for example if in my CMS I have these pages:
About Us (enabled)
Shipping & Refund (disabled)
Terms and Conditions (enabled)
Contacts (enabled)
then the menu would look like:
About US | Terms and Conditions | Contacts
I need just a few tips on how to get started; maybe somebody has already done this before?
Dougle
thanks a lot, that was really helpful!
Fede
in Magento CMS you can make static pages that you can only access using its IDENTIFIER; what I wanted is somehow make a menu that will automatically display the ACTIVE (enabled) static pages; and if you set status to Disable it should not be in the menu;
here is the code i used, note there is IF $PageData['identifier']!='no-route'; no-rute is the 404 page, so i don't need it in the menu, but it must be enabled so Magento redirects 404 errors to this page;
<div>
<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php $collection->getSelect()
->where('is_active = 1'); ?>
<ul>
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php if($PageData['identifier']!='no-route') { ?>
<li>
<?php echo $PageData['title'] ?>
</li>
<?php } ?>
<?php endforeach; ?>
</div>
To exclude more than just the no-route I added a new field to the CMS pages to specify if the page should have a menu item or not using true or false. I followed Add a new CMS Field and used the following in main.php
$fieldset->addField('menu', 'text', array(
'name' => 'menu',
'label' => Mage::helper('cms')->__('On Menu'),
'title' => Mage::helper('cms')->__('On Menu'),
'required' => true,
'disabled' => $isElementDisabled
));
Then changed this line:
<?php if($PageData['identifier']!='no-route') { ?>
to
<?php if($PageData['menu']!= 'false') { ?>
Here is another way to put static links to Magento catalog menu.
First, create static page, assign some url key to it, for example, "my-test-page".
Go to /app/code/core/Mage/Catalog/Block, copy file Navigation.php to /app/code/local/Mage/Catalog/Block, now you able to edit it without any worries about the possibility of loosing your changes with Magento upgrade.
Open file Navigation.php at line 265 (magento 1.4) function _renderCategoryMenuItemHtml(...), change code:
$htmlLi .= '>';
$html[] = $htmlLi;
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
to that:
$htmlLi .= '>';
$html[] = $htmlLi;
if(preg_match('/\/static-/', $this->getCategoryUrl($category))) {
$link_url = str_replace("static-", "", $this->getCategoryUrl($category));
} else {
$link_url = $this->getCategoryUrl($category);
}
$html[] = '<a href="'.$link_url.'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
Now go to Categories management, edit category, change URL key to that: "static-my-test-page" and uncheck "Create Permanent Redirect for old URL" check-box. After saving category you will have link to my-test-page at top categories menu in Magento.
So after all that changes you can convert category link to static page link by adding prefix "static-" to category URL key.
In your page/html block create a method containing:
$collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());
$collection->getSelect()
->where('is_active = 1')
->order('main_table.sort_order ASC');
return $collection;
Which you can call in your template and foreach() through creating your LIs
Might need some tweaking mind, depending on your setup.
From memory though i think this is built in, have a look in design/frontend/../../templates/page/ i seem to remember striping out some similar functionality in one of the phtml files in there.
where, order and other select stuff can be found in /lib/Zend/Db/Select.php(FYI)

Categories