I wonder how to define template for each level in pdoMenu params if I want to make multilevel menu on my webpage?
For example the structure for menu is something like this:
<ul>
<li>
<div></div>
<img src="assets/img/1.png" />
<a>Link 1</a>
<ul>
<li>
<a>Sub link 1</a>
</li>
<li>
<a>Sub link 2</a>
</li>
</ul>
</li>
<li>
<div></div>
<img src="assets/img/2.png" />
<a>Link 2</a>
<ul>
<li>
<a>Sub link 1</a>
</li>
<li>
<a>Sub link 2</a>
</li>
</ul>
</li>
</ul>
As you can see first level of menu includes div and img tags but second does not.
That is why I need to define different templates via pdoMenu.
Unfortunately, there is no comprehensive examples for pdoMenu parameters.
It seems that pdoMenu provides this feature only for "&levelClass" parameter which gives incrementation for css class for each level.
May be I should use some other approach for this purpose? Pdoresources or getresources?
Wayfinder does have some menu template options you could explore: https://docs.modx.com/extras/evo/wayfinder#Wayfinder-TemplateParameters
But, for the time being, the only way I could think to do this would be to use getResources.
For your first level you would use a simple getResources call that restricts it to 1 level of depth, but in that .tpl you would have a 2nd getResources call.
For example:
[[!getResources?
&parents=`1`
&depth=`1`
&tpl=`firstLevel`
]]
Then firstLevel would look something like:
<li>
[[+pagetitle]]
[[!getResources?
&parents=`[[~[[+id]]]]`
&depth=`0`
&tplWrapper=`menuWrapper`
&tpl=`secondLevel`
]]
</li>
menuWrapper would just wrap secondLevel and look like:
<ul>[[+output]]</ul>
secondLevel would just look like:
<li>
[[+pagetitle]]
</li>
This is one way to go about it. The above is untested so you might want to keep that in mind.
As a side note, if you only want to add images you can use css, eg:
li ul li:first-child:before {
content: url('../images/image.png');
}
Related
I'm new to wordpress.
Is it possible to use original HTML for navigation menu and edit its titles and URLs in wordpress admin?
My navigation HTML looks like this.
<nav>
<ul id="menu">
<li><a>Menu1</a>
<div class="slideToggleThis">
<ul>
<li><a>Menu1-1</a>
<ul>
<li>Menu1-1-1</li>
<li>Menu1-1-2</li>
<li>Menu1-1-3</li>
</ul>
</li>
<li><a>Menu1-2</a>
<ul>
<li>Menu1-2-1</li>
<li>Menu1-2-2</li>
<li>Menu1-2-3</li>
</ul>
</li>
</ul>
</div>
</li>
</ul>
<ul id="hamburger">
<li><a id="hamburgerFont"></a>
<ul>
<li><a>MenuS</a>
<ul>
<li>MenuA</li>
<li>MenuB</li>
<li>MenuC</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
As you can see from this, my nav has div between ul and li. The div is necessary because the nav is arranged with Flexbox, thus slideToggle from JQuery doesn't work properly without it (slideToggle changes affected elements' display to block which is not good for display: flex;).
As long as I know, HTML code created by "?php wp_nav_menu(); ?" is simple combination of ul and li which is different from mine.
Are there any solution for me to edit my original HTML navigation menu in wordpress admin? or should I manually change the php files every time I change the contents in the menu?
Thank you for reading.
There is a way of changing the structure of the WordPress menu. I'm not that good in explaining the exact code but this url may help you:
https://github.com/roikles/Wordpress-Bem-Menu
He creates a new navigation setup, based on BEM method, to create a new structure.
By calling bem_menu( you can add the navigation (read docs for more info). Here you can adjust your settings.
Hello i recently just got my web server to run all .html files as .php files which now allows me to use the php include function, which is very useful.
However i have multiple sub directories with multiple files in each.
Homepage
--banners
--banner2.html
--banner2.html
--signs
--sign1.html
and so on. The problem here is im trying to use include for my top nav bar. when i include the bar in the sub files, for example banner2.html it wont correctly link.
nav.php
<ul class="nav navbar-nav">
<li>
About
</li>
<li>
Services
</li>
<li>
Contact
</li>
<li>
Login
</li>
<li>
Logout
</li>
<li>
<img src="images/Cart.gif" style="height: 20px; width:20px;"> Cart
</li>
</ul>
in the nav bar is a link to about.html normally i would do the
about
however i cant do that when every file is going to share the same navigation bar.
How can I fix this?
I have answered my own quest and feel silly for even asking the question. I just used absoulte paths
nav.php
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
About
</li>
<li>
Services
</li>
<li>
Contact
</li>
<li>
Login
</li>
<li>
Logout
</li>
<li>
<img src="images/Cart.gif" style="height: 20px; width:20px;"> Cart
</li>
</ul>
There are some ways to fix this, one of them is:
Use $_SERVER["DOCUMENT_ROOT"] – We can use this variable to make all our includes relative to the server root directory, instead of the current working directory(script’s directory). Then we would use something like this for all our includes:
`about`
Also you should check this post.
You could use the relative path to the root directory which is /file.ext
Example:
About
In TYPO3 I used html blocks which contains a nav of hash-tags
<li class="navbox default">
About us
</li>
<li class="navbox default">
Shop
</li>
<li class="navbox default">
Images
</li>
<li class="navbox default">
News
</li>
<li class="navbox default">
Sale
</li>
<li class="navbox default">
Contact us
</li>
This nav is used for Bootstraps Scroll-Spy and the hash-tags represent content-elements. Everything works fine, but only for the page "/". If I open the page in another language like /de.html or /en.html, TYPO3 prepend this part to the href and I get something like this
About us
This is fine for most cases, but Bootstraps Scroll-Spy expect all links as a "pure" Hash without anything in front.
My question is now, how can I disable TYPO3 parsing of html blocks/link replacement? I don't want to modify the bootstrap js files
config.prefixLocalAnchors = 0 is your friend if it is compatible to the rest of your environment (e.g. RealURL configuration):
http://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html?highlight=prefixlocalanchors
I have the following dynamic output generated by Joomla for page navigation.
<ul>
<li class="pagination-start">
<span class="pagenav">Start</span>
</li>
<li class="pagination-prev">
<span class="pagenav">Prev</span>
</li>
<li>
<span class="pagenav">1</span>
</li>
<li>
<a title="2" href="link-to-page-2" class="pagenav">2</a>
</li>
<li class="pagination-next">
<a title="Next" href="link-to-next-page" class="pagenav">Next</a>
</li>
<li class="pagination-end">
<a title="End" href="link-to-last-page" class="pagenav">End</a>
</li>
</ul>
I need only the link data of the next page i.e. link-to-next-page which is wrapped by <li class="pagination-next"></li>
I need to do it in PHP so that I can make use of the same the same for my Infinite Scrolling plugin.
I can do it through jQuery but it will not serve the purpose. I am looking for a PHP solution to get this.
Can someone please help me?
Use the following in your jquery code:
navSelector : '.pagenav', // selector for the paged navigation
nextSelector : '.pagenav a[title="Next"]', // selector for the NEXT link (to page 2)
I have not debugged the above code, simply adapted it from Joomla 1.5 (see here)
I have an array of data I want to output as a UL using PHPTAL (easy) with class attributes supplied by the array (easy), a class attribute for first and for the last element (easy)... all at the same time (hard).
Ie. I want to combine:
<ul tal:repeat="item items">
<li class="${item/class}">${item/text}</li>
</ul>
with this
<ul tal:repeat="item items">
<li tal:attributes="class repeat/item/first 'first'">${item/text}</li>
</ul>
and this
<ul tal:repeat="item items">
<li tal:attributes="class repeat/item/last 'last'">${item/text}</li>
</ul>
This is purely presentational stuff, so I'd rather do it purely in PHPTAL. Is this possible? How?
No, there's no pure TALES for this.
<li tal:attributes="class php:repeat.item.last ? 'last'
: (repeat.item.first ? 'first' : NULL)">
This is a pretty old thread, but because no one mentioned it: an 'cleaner' way is probably through a custom modifier. (http://phptal.org/manual/en/split/custom-modifiers.html). Then you could have:
<li tal:attributes="class css-ordinal:repeat.item">
and as a benefit, you could reuse that in other elements, as it seems a pretty general idiom.