How to set first menu active in mega menu? - php

I am trying to create a hoverable mega menu, all works fine except the active one.
I checked in source codes and active class is added, but it doesn't show up the content until mouseenter on it.
see image please :
And this is when I go on it with mouse, it show up with no problem.
I gues I need to set main (FINANCE is main menu in pic) menu active, but dont know how to pass it to submenu.
Here is my full code :
$stmt_menu = $pdo->prepare("SELECT * FROM categories WHERE parentId = ? LIMIT 5");
$stmt_menu->execute([0]);
if ($stmt_menu->rowCount() > 0) {
$query = $stmt_menu->fetchAll();
foreach ($query as $row) {
if ($row['cat_type'] == 'mega') {
?>
<li class="dropdown megamenu-fw mega-li-<?php echo $row['catId']; ?>">
<?php echo $row['catName']; ?><span class="caret"></span>
<ul class="dropdown-menu megamenu-content dropdown-top" role="menu" aria-expanded="true" data-mega-ul="<?php echo $row['catId']; ?>">
<li>
<?php
$stmt_menu = $pdo->prepare("SELECT * FROM categories WHERE parentId = ? LIMIT 5");
$stmt_menu->execute([$row['catId']]);
if ($stmt_menu->rowCount() > 0) {
$subquery = $stmt_menu->fetchAll();
?>
<div class="sub-menu-left">
<ul class="nav-sub-categories">
<?php
$i = 0;
foreach ($subquery as $subq) {
$actives = '';
if($i == 0){
$actives = ' active';
}
?>
<li data-category-filter="<?php echo $subq['cat_seo_url']; ?>-<?php echo $subq['catId']; ?>" class="li-sub-category<?php echo $actives; ?>"><?php echo $subq['catName']; ?></li>
<?php
$i++;
}
?>
</ul>
</div>
<div class="sub-menu-right">
<?php
$i = 0;
foreach ($subquery as $subcats) {
$actives = '';
if($i == 0){
$actives = ' active';
}
?>
<div class="sub-menu-inner filter-<?php echo $subcats['cat_seo_url']; ?>-<?php echo $subcats['catId']; ?><?php echo $actives; ?>">
<div class="row row-menu-right">
<div class="col-sm-3 menu-post-item">
<div class="post-item-image">
<a href="is-allowance-instantly-strangers-applauded">
<img src="assets/img/img_bg_md.png" data-src="uploads/images/202203/image_380x226_624239afd7295.jpg" alt="Is allowance instantly strangers applauded" class="lazyload img-responsive img-post" width="1" height="1"/>
</a>
</div>
<h3 class="title"><?php echo $subcats['cat_seo_url']; ?> Is allowance instantly strangers applauded</h3>
<p class="post-meta">
admin
<span>Mar 28, 2022</span>
<span><i class="icon-comment"></i>2</span>
<span class="m-r-0"><i class="icon-eye"></i>894</span>
</p>
</div>
</div>
</div>
<?php
$i++;
}
?>
</div>
<?php
}
?>
</li>
</ul>
</li>
<?php
} elseif ($row['cat_type'] == 'dropdown') {
echo ' <li class="nav-item"><a class="nav-link" href="' . $row["cat_seo_url"] . '">test</a></li>';
} else {
echo ' <li class="nav-item"><a class="nav-link" href="' . $row["cat_seo_url"] . '">' . $row["catName"] . '</a></li>';
}
}
}

Related

Adding Image to Carousel Slider

enter image description here
<div id="demo" class="carousel slide" data-ride="carousel">
<?php $count = count($veriler);?>
<ul class="carousel-indicators">
<?PHP
$i=0;
for ($i=0;$i<$count;$i++) { ?>
<li data-target="#demo" data-slide-to="<?php echo $i; ?>"></li>
<?php } ?>
</ul>
<div class="carousel-inner">
<?php
$j=0;
foreach ($veriler as $row) { ?>
<div class="item <?php if($j==0) { echo "active"; } ?>">
<div style="max-width:1100px; max-height:500px;">
<img src=" <?php echo $row["haberekle_konu"]; ?>" alt="Los Angeles">
</div>
<div class="carousel-caption">
<h3> <?php echo $row["haberekle_baslik"]; ?> </h3>
</div>
</div>
<?php $j++; } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
i want to add in Carousel Slider a few images.
i posted image and caption from admin panel and i saved to database. when i extracted data from the database, result that: See i added the image. No picture display.
enter image description here
<?php
$veriler = $db->query("SELECT * FROM haberlerekle",PDO::FETCH_ASSOC)->fetchAll();
?>
i think, that codes need.
The symbol the top left cornor(https://i.stack.imgur.com/7UgIN.jpg) indicates a "broken link".
This means, the path does not point on a File.
Or u maybe need a absolute/relativ path(HTML showing broken image)
Make sure the path of the image u try to paste in the src-attribute is realy there.
U can try it by pasting the content of
$row["haberekle_konu"]
behind the URL.
If the image not appear, the path ist not correct.
Eventually i found the codes i was looking for. i found youtube. The codes and youtube link below.
Youtube Link
slider.php
<?php
$veriler = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id DESC LIMIT 12",PDO::FETCH_ASSOC)->fetchAll();
/* $veriler = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id DESC LIMIT 7"PDO::FETCH_ASSOC)->fetchAll(); */
?>
<div id="demo" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<?php
$i = 0;
foreach ($veriler as $row) {
$actives = '';
if($i == 0) {
$actives = 'active';
}
?>
<li data-target="#demo" data-slide-to="<?php echo $i; ?>" class="<?php echo $actives; ?>"></li>
<?php $i++; } ?>
</ul>
<div class="carousel-inner">
<?php
$i = 0;
foreach ($veriler as $row) {
$actives = '';
if($i == 0) {
$actives = 'active';
}
?>
<div class="carousel-item <?php echo $actives; ?>">
<img src="upload/images/<?php echo $row['haberekle_konu']; ?>" width="832" height="502">
<div class="carousel-caption">
<p><?php echo $row["haberekle_baslik"]; ?></p>
</div>
</div>
<?php $i++; } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
admin.php
<?php
if(isset($_POST['resimyukle'])) {
$yazi = $_POST['haberekle_baslik'];
$yukleklasor = "../../../upload/images";
$tmp_name = $_FILES['yukle_resim']['tmp_name'];
$name = $_FILES['yukle_resim']['name'];
$boyut = $_FILES['yukle_resim']['size'];
$tip = $_FILES['yukle_resim']['type'];
$uzanti = substr($name,-4,4);
$rasgelesayi1 = rand(10000,50000);
$rasgelesayi2 = rand(10000,50000);
$resimad = $rasgelesayi1.$rasgelesayi2.$uzanti;
//dosya var mı kontrol
if(strlen($name) == 0) {
echo "Bir Dosya Seçiniz";
exit();
}
//boyut kontrol
if($boyut > (1024*1024*3)) {
echo "Dosya Boyutu Çok Fazla";
exit();
}
//tip kontrol
if($tip != 'image/jpeg' && $tip != 'image/png' && $uzanti != '.jpg') {
echo "Yalnızca jpeg veya png formatında olabilir";
}
move_uploaded_file($tmp_name, "$yukleklasor/$resimad");
$resimsor = $db->prepare("INSERT INTO haberlerekle set haberekle_konu=:ad, haberekle_baslik=:baslik");
$resimyukle = $resimsor->execute(array('ad'=> $resimad, 'baslik'=> $yazi));
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="haberekle_baslik" size="100"></input><br><br>
<input type="file" name="yukle_resim" /><br>
<input type="submit" value="Yükle" name="resimyukle" />
</form>
Thank you for your help.

The problem of cannot pass ?= value in php pagination

I have do a pagination with php&html,the problem is my $page is always equal 1 even I click another page and the url is already become ?page=2.The value $p cannot pass as $page.How can I solve this?
<ul class="nospace clear" style="width:1310px;">
<?php
if(isset($_GET['page'])&& $_GET['page']!=""){$page = $_GET["page"];}else{$page=1;}
$current=$page;
$end=12;
if($page=1){$start=0;$previous=$page;$next=$page+1;}
else if($page<=12){$start=$page*12-12;$previous=$page-1;$next=$page+1;}
else{$start=0;$previous=$page-1;$next=12;}
$sql = "Select * from item where Gender='women' AND Category='cloth' LIMIT $start,$end";
$result = mysqli_query($connect,$sql);
while($row=mysqli_fetch_assoc($result)){?>
<img src="../images/demo/<?php echo $row["Pic"]; ?>" style="width:300px;height:280px"><br><p></p><h3><strong><?php echo $row["Name"]; ?></strong></h3><p><?php echo $row["Description"]; ?></p></li>
<?php } ?></ul><figcaption>Page <?php echo"$page ";?> end...</figcaption>
</figure>
</div>
<nav class="pagination">
<ul>
<li>« Previous</li>
<?php
for ($p=1;$p<13;$p++){
if ($page == $p) {?>
<li class="current btn1"><strong><?php echo $p ?></strong></li><?php }
else{?><li><a href="?page=<?php echo $p ?>" class='btn1'><?php echo $p ?></a></li><?php }}?>
<li> Next » </li>
</ul>

Magento if subItems is active add class to subitem parent

Hi i want to add active class to li tag when a subItems menu is active. My code below:
<?php foreach ($items as $key => $item) : ?>
<?php
$subItems = $block->getMenuItems($key);
$class = '';
if (count($subItems) > 0) {
$class .= 'dropdown ';
}
if ($block->isActive($item)) {
$class .= 'active ';
}
?>
<li class="c-sidebar__item <?php /* #escapeNotVerified */ echo $class; ?>">
<?php if (count($subItems) > 0) : ?>
<a class="c-sidebar__link" href="#">
<div class="c-sidebar__item-content">
<i class="c-sidebar__item-icon c-sidebar__item-icon--main glyphicon glyphicon-dashboard"></i>
<p class="c-sidebar__item-name"><?php echo __($item['label']); ?></p>
<i class="c-sidebar__item-icon c-sidebar__item-icon--carot glyphicon glyphicon-menu-down"></i>
</div>
</a>

How increment a number in wordpress page?

I have a page where i generate a multiple ID's and i put in page, is ads page like that:
if you see in my page i have that message: The number is: 1 after every ad
I want to increment that number, i try this but i can when de page is in loading my x is alwais 1:
<?php
$x = 1;
if($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
I want to increment always in my page 1,2,3,4,5 not always 1, but how can i do
Above i put all my code from page:
<?php
global $ae_post_factory, $user_ID;
$place_obj = $ae_post_factory->get('place');
$post = $place_obj->current_post;
// et_location_lat et_location_lng
?>
<?php
$query = $wpdb->get_var('SELECT count(*) as featured FROM `eHouTHuQpostmeta` WHERE `post_id`=' . get_the_ID() . ' and meta_key = "et_featured" and meta_value=1');
$date = $wpdb->get_var('SELECT meta_value FROM `eHouTHuQpostmeta` WHERE `post_id`=' . get_the_ID() . ' and meta_key = "et_twitter_url" ');
$hour = $wpdb->get_var('SELECT meta_value FROM `eHouTHuQpostmeta` WHERE `post_id`=' . get_the_ID() . ' and meta_key = "et_google_url" ');
?>
<li <?php post_class( 'post-item' ); ?> >
<div style="width:100%">
<div style="float:left;width:50%">
<?php if($query == 1){ ?><STRONG>SUGGESTED</STRONG><?php } ?>
</div>
<div style="float:right;width:50%;text-align:right">
<?php
if($date != "" && $hour != ''){
echo "<span id='data-time'>" . $date . "</span>";
}
?>
</div>
<div style="clear:both"></div>
</div>
<div class="place-wrapper<?php if($query == 1){ echo " featured-box"; } ?>">
<a href="<?php the_permalink(); ?>" class="img-place">
<img src="<?php echo $post->the_post_thumnail; ?>" alt="<?php the_title(); ?>"/>
<?php if(isset($post->et_google_url) && $post->et_google_url){ ?>
<div class="cat-<?php echo $post->place_category[0]; ?>">
<div class="ribbon">
<span class="ribbon-content"><?php echo $post->et_google_url; ?></span>
</div>
</div>
<?php } ?>
</a>
<div class="place-detail-wrapper">
<h2 class="title-place"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?>
</a></h2>
<span class="address-place">
<i class="fa fa-map-marker"><span itemprop="latitude" id="latitude" content="<?php echo $post->et_location_lat;?>"></span></i>
<span itemprop="longitude" id="longitude" content="<?php echo $post->et_location_lng;?>"></span>
<span class="distance"></span>
<?php echo $post->et_full_location; ?>
</span>
<span class="address-place">
<?php echo strip_tags(html_entity_decode(get_the_excerpt())); ?>
<hr>
</span>
<div class="rate-it" data-score="<?php echo $post->rating_score; ?>">
</div>
<?php
if (!empty($post->et_fb_url)) {
echo "<span class='imageContainer'> <i class='fa fa-usd' style=''>" . $post->et_fb_url . '</i></span>';
}
?>
</i>
</div>
<?php
if(#wp_get_current_user()->user_login == get_the_author())
{
?>
<!--<div class="place-config">
<i class="fa fa-cog edit-config"></i>
<img src="http://romanianusa.com/wp-content/uploads/2015/12/1450310691_6.png" class="edit-config" style="width:22px;height:22px;">
</div>
<div class="edit-place-post">
<a href="http://romanianusa.com/post-place?id=<?php the_ID(); ?>"><i class="fa fa-history place-remove fa-3x" style="padding-right:50px"></i>
<i class="fa fa-pencil place-edit fa-3x" style="padding-right:50px; padding-top:15px"></i>
<i class="fa fa-trash-o place-remove fa-3x" style="padding-top:15px"></i>
<br>
<span style="padding-right:52px">Repost</span>
<span style="padding-right:52px;">Edit</span>
<span style="padding-right:8px;">Trash</span>
</div>-->
<?php
}
?>
</div>
<?php
$x = 1;
if($x <= 5) {
echo "The number is: $x <br>";
}
$x++;
?>
<?php
if (!empty($post->et_url)) {
?>
<!--<center><span id="flag"><?php echo $post->et_url; ?></span></center>-->
<center><?php echo $post->et_url; ?></center>
<?php
}
?>
</li>

CSS Dropdown menu through PHP, logic defeats me

My brain doesn't seem to want to work this morning.. i have the following array:
private $nav_pages = [['0', 'Home', 'home'],
['0', 'About Us', 'about'],
['0', 'Our Services', 'services'],
['1', 'PROCURE TO PAY (P2P)', 'procure'],
['1', 'ORDER TO CASH (02C)', 'cash'],
['1', 'GENERAL ACCOUNTING', 'general'],
['2', 'Charting of Accounts', 'charting'],
['2', 'General Ledger Maintenance', 'maintenance'],
['2', 'Accounts Receivable Services', 'receivable'],
['2', 'Accounts Payable Services', 'payable'],
['2', 'Reconciliation of Bank Accounts and Credit Cards', 'reconciliation'],
['2', 'Preparing Financial Statements', 'statements'],
['2', 'Payroll Processing', 'payroll'],
['1', 'CLOSING & REPORTING', 'closing'],
['0', 'How It Works', 'how-it-works'],
['0', 'Contact Us','contact'],
['0', 'Careers', 'careers']];
This is then fed to a php page which is meant to lay out a multi-layered pure css drop down menu.. the php page code is:
<ul class="<?php echo $ul_class; ?>">
<?php $this_layer = 0;
// place array content into variables
foreach ($links as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
if ($item_layer > $this_layer) { ?>
<ul>
<?php $this_layer++; }
elseif ($item_layer == $this_layer) { ?>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
</li>
<?php }
elseif ($item_layer < $this_layer) { ?>
</li></ul>
<?php $this_layer--; } ?>
<?php } ?>
The output is not correct however as the above code always closes the list item containing the second layer before the second layer is ready to be closed. if that makes sense..
<ul class="pages_nav">
<li class="home">
<a class="home"
href="/home">
Home
</a>
</li>
<li class="about">
<a class="about"
href="/about">
About Us
</a>
</li>
<li class="services">
<a class="services"
href="/services">
Our Services
</a>
</li>
<ul>
<li class="cash">
<a class="cash"
href="/cash">
ORDER TO CASH (02C)
</a>
</li>
<li class="general">
<a class="general"
href="/general">
GENERAL ACCOUNTING
</a>
</li>
<ul>
<li class="maintenance">
<a class="maintenance"
href="/maintenance">
General Ledger Maintenance
</a>
</li>
<li class="receivable">
<a class="receivable"
href="/receivable">
Accounts Receivable Services
</a>
</li>
<li class="payable">
<a class="payable"
href="/payable">
Accounts Payable Services
</a>
</li>
<li class="reconciliation">
<a class="reconciliation"
href="/reconciliation">
Reconciliation of Bank Accounts and Credit Cards
</a>
</li>
<li class="statements">
<a class="statements"
href="/statements">
Preparing Financial Statements
</a>
</li>
<li class="payroll">
<a class="payroll"
href="/payroll">
Payroll Processing
</a>
</li>
</li></ul>
</li></ul>
<li class="contact">
<a class="contact"
href="/contact">
Contact Us
</a>
</li>
<li class="careers">
<a class="careers"
href="/careers">
Careers
</a>
</li>
SOLUTION:
<ul class="<?php echo $ul_class; ?>">
<?php $this_layer = 0;
// place array content into variables
foreach ($links as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
// check if link needs to be manipulated
switch($do) {
case 'strtolower':
$item_string = strtolower($item_string);
break;
case 'strtoupper':
$item_string = strtoupper($item_string);
break;
} ?>
<?php if ($item_layer > $this_layer) { ?>
<ul>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php $this_layer++; }
elseif ($item_layer == $this_layer) { ?>
</li><li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php }
elseif ($item_layer < $this_layer) { ?>
</li></ul></li><li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php $this_layer--; } ?>
<?php } ?>
Never close the the li tag, close it when you add something
foreach ($links as $link) {
if ($item_layer > $this_layer) {
echo '<ul><li> ......';
this_layer++;
}elseif ($item_layer == $this_layer) {
echo '</li><li>......';
}elseif ($item_layer < $this_layer) {
echo '</li></ul><li>......';
$this_layer--;
}
}
Last you probably need to add a echo '</li></ul>' outside of the foreach to close everything
Had to rework the code a little, usually i organize the php menu structure in tree form makes it easier to parse into html menus, but here it is:
<ul class="<?php echo $ul_class; ?>">
<?php
$this_layer = 0;
$closeit = false;
// place array content into variables
foreach ($nav_pages as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
if ($item_layer > $this_layer) {
// Changing level, dont close the previous li
?><ul><?php
$closeit = false;
$this_layer++;
}
if ($item_layer == $this_layer) {
// Same level, check if you need to close previous li
if ($closeit) {
?></li><?php
}
// Render the li
?>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php
// Close it on next loop
$closeit = true;
}
elseif ($item_layer < $this_layer) {
// Changing layer back down, close the previous li and the current level ul
?>
</li>
</ul>
<?php
$this_layer--;
}
}
// Finished loop, there should still be a li waiting to be closed
if ($closeit) {
?></li><?php
}
// Close menu
?>
</ul>
Should be working, let me know if it isnt
Suggested php menu structure:
$menu = array(
array(
"url"=>"/place.php",
"text"=>"Go to place"
),
array(
"url"=>"/place2.php", // not necessary
"text"=>"with submenu",
"children"=>array(
array(
"url"=>"/placewithinplace2.php",
"text"=>"submenu item"
)
)
)
);

Categories