I've been stuck on this all morning and I don't think i'm that much further.
I'm trying to display a wordpress menu, I then want to display all the child pages for the parent menu, all the child pages have thumbnails and I want these to show to.
I'me trying to add the thumbnails into the ing tag in the child pages
Here's how I went the code to look
Parent menu
<nav>
<a href="#" >Sample Page 1</a>
<a href="#" >Sample Page 2</a>
</nav>
Child menu
<ul class="sample_page_1">
<li>
<a href="#">
<img src="image.jpg" alt="img05">
<h4>Belts</h4>
</a>
</li>
<li>
<a href="#">
<img src="image.jpg" alt="img05">
<h4>Belts</h4>
</a>
</li>
</ul>
<ul class="sample_page_2">
<li>
<a href="#">
<img src="image.jpg" alt="img05">
<h4>Belts</h4>
</a>
</li>
<li>
<a href="#">
<img src="image.jpg" alt="img05">
<h4>Belts</h4>
</a>
</li>
</ul>
Here's the code I have so far but it's not doing what it should, it's not displaying the images and I can't figure out how? Not even sure it's it the correct way to do it?
<ul>
<?php
$menu_name = 'shoes';
$items = wp_get_nav_menu_items($menu_name);
foreach ( $items as $item){
echo '<li>'.$item->title.'</li>';
}
?>
</ul>
Thanks
Testing this on my end yielded satisfactory results. This will affect ALL menus, so feel free to add additional logic to only target certain menus.
You'll probably have to style it to make it look a bit better, but just drop this into your functions.php file:
add_filter('walker_nav_menu_start_el', 'maiorano_generate_nav_images', 20, 4);
function maiorano_generate_nav_images($item_output, $item, $depth, $args){
if(has_post_thumbnail($item->object_id)){
$dom = new DOMDocument(); //DOM Parser because RegEx is a terrible idea
$dom->loadHTML($item_output); //Load the markup provided by the original walker
$img = $dom->createDocumentFragment(); //Create arbitrary Element
$img->appendXML(get_the_post_thumbnail($item->object_id, 'thumbnail')); //Apply image data via string
$dom->getElementsByTagName('a')->item(0)->appendChild($img); //Append the image to the link
$item_output = $dom->saveHTML(); //Replace the original output
}
return $item_output;
}
Related
I start the adventure with prestashop and I would like to have a problem. I have no idea how to add a classe or ID to the module.
My code is:
<h3>Mini Top Menu</h3>
<ul>
<li>
<a id="link-cms-page-1-3" class="cms-page-link" href=""link1 title="link1">
</a>
</li>
<li>
<a id="link-cms-page-4-3" class="cms-page-link" href="link1" title="link1">
</a>
</li>
<li>
<a id="link-cms-page-5-3" class="cms-page-link" href="link1" title="link1">
</a>
</li>
<li>
<a id="link-product-page-prices-drop-3" class="cms-page-link" href="link1" title="link1">
</a>
</li>
</ul>
I would like to add this <ul> ID and get rid of the <h3> tag
I will add that I use Link Widget.
If I got it right:
You have to search for (menu) module on your theme folder to find .tpl files:
"themes/yourTheme/modules/TargetModule/*.tpl"
if this path not exist then you have to search on "modules/TargetModule/templates/...." to find your file.
Tip: don't forget to clear both PrestaShop and browser cache, after any change on tpls
I am trying to edit my html file using php based on the user input. When i run the code it dose not give me any error but at the same time it does not make any changes to the file.
Here is the PHP code.
$doc = new DOMDocument();
//validate the document
$doc->validateOnParse = true;
//libxml_use_internal_errors(true);
#$doc->loadHTMLFile('index.html');
$doc->formatOutput = true;
//navigating to the ul
$ul=$doc->getElementById('ul');
$href= "/".$account_number."/".$account_number."-".$profile_name.".html";
$element="Acctount_ID:".$account_number;
$ul=$doc->getElementById('homeSubmenu');
//create the li
$li=$doc->createElement('li');
$new_li=$ul->appendChild($li);
//create the link
$a = $doc->createElement('a');
$new_ul= $new_li->appendChild($a);
$new_ul->setAttribute('href', $href );
$new_ul->setAttribute('target','joe');
$new_ul->setAttribute('title', $element);
echo $doc->saveHTML();
include('./index.html');
//end of the php.
?>
Here is the html code.
<ul class="list-unstyled components">
<p>AWS Accounts</p>
<li class="active">
<a href="#homeSubmenu" data-toggle="collapse" aria-
expanded="true" class="">Accounts</a>
<ul class="list-unstyled collapse in" id="homeSubmenu" aria-
expanded="true" style="">
<li><a href="report1/report.html" target="joe">Account
ID: 930621594025</a></li>
<li><a href="report2/report-rahul.html"
target="joe">Account ID: 725840360046</a></li>
<li><a href="report3/report-chenna.html"
target="joe">Account ID: 624704405165</a></li>
</ul>
</li>
<ul class="list-unstyled CTAs">
<li></li>
<li></li>
</ul>
I have a menu at the top of the page. On the bottom below the article I want to show the submenu items that are children or siblings of the active menu item (the item that I clicked on to get to the page in question).
That is, if I clicked on "Submenu item A" I want to see "Submenu item A" and "Submenu item B" in the bottom menu.
I want to do this using php or css, but not using javascript.
I don't want this to happen "on the fly" when hovering or something. I just want to show the childs and siblings of current item when that item has been clicked and I'm already on the target page to aid the user in navigating through the whole category.
Snippet showing what I want it to look like when "Menu item 1" or any of its submenu items are opened.
<ul>
<li>
Menu item 1
<ul>
<li>
<a href='item-1/item-a'>
Submenu item A
</a>
</li>
<li>
<a href='item-1/item-b'>
Submenu item B
</a>
</li>
</ul>
<li>
<a href='item-2'>
Menu item 2
</a>
<li>
</ul>
<article>Page contents</article>
<ul>
<li>
<a href='item-1/item-a'>
Submenu item A
</a>
</li>
<li>
<a href='item-1/item-b'>
Submenu item B
</a>
</li>
<ul>
Wrap the bottom ul with this code in php.
This script check if the path contains item-1, if so, he shows the ul otherwise it didn't.
<?php
$url = $_SERVER['REQUEST_URI'];
$url_parts = parse_url($url);
if (strpos($url_parts["path"], 'item1') !== false) {
?>
<ul>
<li>
<a href='item-1/item-a'>
Submenu item A
</a>
</li>
<li>
<a href='item-1/item-b'>
Submenu item B
</a>
</li>
<ul>
<?php } ?>
This can't be done with CSS alone. For it to work with PHP and no Javascript it will only change on page load.
How can I create a function to scan all menu items from Drupal 7 system and if there is a nested ul, add dropdown CSS classes to the nested ul and add a custom attribute to the parent li container? Im using UIKIT which will automatically create the dropdowns.
Here's my current menu HTML output:
<ul class="menu">
<li class="first last expanded">
<a title="" href="/node/add">Add content</a>
<ul class="menu">
<li class="first leaf">
<a title="article" href="/node/add/article">Article</a></li>
<li class="leaf">
<a title="page" href="/node/add/page">Basic page</a></li>
<li class="last leaf"><a title="blog" href="/node/add/blog">Blog entry</a></li>
</ul>
</li>
</ul>
Here's what I need it to be:
<ul class="menu">
<li class="first last expanded" data-uk-dropdown>
<a title="" href="/node/add">Add content</a>
<ul class="menu uk-dropdown">
<li class="first leaf">
<a title="article" href="/node/add/article">Article</a></li>
<li class="leaf">
<a title="page" href="/node/add/page">Basic page</a></li>
<li class="last leaf"><a title="blog" href="/node/add/blog">Blog entry</a></li>
</ul>
</li>
</ul>
Im looking for the simplest approach possible.
You can crawl menu tree your self and write out menu HTML as you like. Used that and should be something like:
$tree = menu_tree_all_data('menu_machine_name');
Also, if I remember well, if you do only that your active (current) menu item won't be marked any way, and for marking it you have to also call (after getting $tree variable) :
menu_tree_add_active_path($tree);
But again, if I remember well, that function is only available if you install "Menu block" module...
Print out $tree variable after that and organize your code to crawl recursively menu tree you collected.
I'm trying to split some html content using php's preg-match-all function:
<li class="cat-item"><a title="blabla" href="#">parent 1</a>
<ul class="children">
<li class="cat-item"><a title="" href="#">child 1</a></li>
</ul>
</li>
<li class="cat-item cat-item-4"><a title="blabla" href="#">father 2</a>
<ul class="children">
<li class="cat-item"><a title="" href="#">child 1</a></li>
<li class="cat-item"><a title="bla" href="#">child 2</a></li>
</ul>
</li>
I want to be able to change the link description, for example;
<a title="" href="#">child 1</a>
to
<a title="" href="#">I changed that</a>
while keeping the structure of the original html.
so far, I succeeded to split the links using :
$results = preg_match_all('/<a\s[^>]*href\s*=\s*(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/siU', $html, $tokens);
foreach ( $tokens[0] as $category)
{
echo $category.'<br>';
}
the drawback of this is that it discards child lists, and outputs all the list items in the same level; no distinction between parent and child.
any idea to keep original hierarchy?
thanx :)
use preg_replace to replace strings! something like this here:
$output = preg_replace("/^([123]0|[012][1-9]|31)(\\.|-|\/|,)(0[1-9]|1[012])(\\.|-|\/)(19[0-9]{2}|2[0-9]{3})$/","$1",$in_nn_date);
where $1 or $2 is the thing you have searched with regex and grouped in.
best would be that you use some online editor or something... like this one
and try there! hope it helps...