How to use sub(sub)Categories in Joomla! K2 - php

I'm editing a website, and this site uses data-groups, of which I'm not familiar (enough) with.
The current result is:
• In K2, I have items in categories, subcategories, and sub-subcategories.
• On the page of the items, there is a horizontal lign, showing each subcategory.
• On that page, I added a dropdown menu under one subcategory. In that dropdown, I have a few sub-subcategories. I would like that when I click on that sub-subcategory, it will show the items from that sub-subcategory.
What do I need to do to make this work?
If I need to post more, feel free to ask, and sorry.
I'll try to explain as good as possible:
Category.php
defined('_JEXEC') or die;
?>
<p style="text-align:center;font-weight:bold;font-size:120%;padding:1%;background:#007dbe;color:white;margin:1% 0 0.95% 0;">OUTLET</p>
<!--<img src="https://i.ibb.co/3dk77DK/outlet3.png" style="margin: 0 0 1% 0;">-->
<div class="centered-pills" style="width:98%;margin:0 auto;background:#474747;">
<ul class="nav nav-pills" id="outlet">
<li class="filterTitle">Filter op:</li>
<li class="active" id="pointer">All</li>
<li class="active" id="drop-a-down">Example
<ul class="drop-a-content">
<div class="column-outlet">
<ul><strong>Tools</strong>
<li class="force-css" data-group="Light">Tool 1</li>
<li class="force-css" data-group="Light">Tool 2</li>
<li class="force-css" data-group="Light">Tool 3</li>
</ul>
<ul><strong>Light</strong>
<li class="force-css" data-group="Light">Light 1</li>
<li class="force-css" data-group="Floor">Light 2</li>
<li class="force-css">Light 3</li>
<li class="force-css">Light 4</li>
</ul>
<ul><strong>Tools</strong>
<li class="force-css">Manual tools</li>
<li class="force-css">Electric tools</li>
</ul>
</div>
<div class="column-outlet">
<ul><strong>Other</strong>
<li class="force-css">Other 1</li>
<li class="force-css">Other 2</li>
<li class="force-css">Other 3</li>
</ul>
<ul><strong>Roof</strong>
<li class="force-css">Roof 1</li>
<li class="force-css">Roof 2</li>
<li class="force-css">Roof 3</li>
<li class="force-css">Roof 4</li>
</ul></div>
</ul>
</li>
<li class="active" id="drop-a-down">Animals
<ul class="drop-a-content">
<div class="column-outlet">
<ul><strong>Blocks</strong>
<li class="force-css">Block 1</li>
<li class="force-css">Block 2</li>
<li class="force-css">Block 3</li>
</ul>
<li class="active" data-group="Category-2">Cats</li>
<li class="active" data-group="Category-3">Dogs</li>
<li class="active" data-group="Category-4">Birds</li>
<li class="active" data-group="Category-5">Elephants</li>
<li class="active" data-group="Category-6">Tigers</li>
<li class="active" data-group="Category-7">Lions</li>
<li class="active" data-group="Category-8">Other</li>
<?php foreach($this->subCategories as $key=>$subCategory): ?>
<li data-group="<?php echo $subCategory->name; ?>"><?php echo $subCategory->name; ?></li>
<?php endforeach; ?>
</ul>
</div>
<div style="text-align:center;margin-top:2%;">
Get your products now!
</div>
<div style="clear:both;"></div>
<div class="inner">
<div class="row" style="margin-top:-5%;">
<?php if($this->params->get('subCategories') && isset($this->subCategories) && count($this->subCategories)): ?>
<div class="col-md-12 col-xs-12">
<div class="centered-pills" style="width:98%;margin:0 auto;">
<ul class="nav nav-pills">
<li class="filterTitle">Filter:</li>
<li class="active" data-group="All">Alle</li>
<?php foreach($this->subCategories as $key=>$subCategory): ?>
<li data-group="<?php echo $subCategory->name; ?>"><?php echo $subCategory->name; ?></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php else: ?>
<div class="col-md-12 col-xs-12">
<p class="text-center" style="display:none;">Promotions in: <span class="divider"></span><strong><?php echo $this->category->name; ?></strong> <span class="divider"></span>Show all products</p>
</div>
<?php endif; ?>
<?php if(isset($this->leading) && count($this->leading)): ?>
<ul id="grid">
<?php foreach($this->leading as $key=>$item): ?>
<?php $this->item=$item; echo $this->loadTemplate('item'); ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<div style="text-align:center;margin-top:2%;font-style:italic;font-size:75%;">
All products are property of us.
</div>
</div>
<?php if($this->params->get('catDescription')): ?>
<div class="row">
<div class="col-md-12 col-xs-12">
<div class="disclaimer">
<?php echo $this->category->description; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
Jquery
/* initialize shuffle plugin */
var $grid = jQuery('#grid');
$grid.shuffle({
group: 'all',
itemSelector: '.portfolio-item', // the selector for the items in the grid
speed: 500 // Transition/animation speed (milliseconds)
});
/* reshuffle when user clicks a filter item */
jQuery('.nav-pills li').click(function (e) {
e.preventDefault();
// set active class
jQuery('.nav-pills li').removeClass('active');
jQuery(this).addClass('active');
// get group name from clicked item
var groupName = jQuery(this).attr('data-group');
// reshuffle grid
$grid.shuffle('shuffle', groupName );
});
});

Related

I want to get latest posts on WordPress to below special HTML

I want to get the latest posts on WordPress to below HTML. Can anyone tell me how to code? Thanks!
<div class="cols">
<div class="col1">
<ul class="colList">
<li>post title 1</li>
<li>post title 2</li>
</ul>
</div>
<div class="col2">
<ul class="colList">
<li>post title 3</li>
</ul>
<ul class="rowList">
<li>post title 4</li>
</ul>
</div>
<div class="col3">
<ul class="colList">
<li>post title 5</li>
<li>post title 6</li>
</ul>
</div>
</div>

HTML menu to PHP with Bootstrap not look the same

I have my menu styled with Bootstrap. My dropdown menu was like that with html+bootsrap:
`
<div class="container">
<div class="row">
<ul class="col-sm-3">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul class="col-sm-3">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul class="col-sm-3">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul class="col-sm-3">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</div>
</div>
I used the class col-sm-3 every 4 items to achieve that.
But i cant do that in php cause i am using foreach loop and the result is like this one:
I tried with col-sm-3 but not..
<div class="collapse navbar-collapse btnCollapse">
<ul class="nav navbar-nav">
<li>Home</li>
<?php foreach ($navItems as $item) { ?>
<li class="dropdown">
<?php echo $item['title']; ?><span class="caret"></span>
<?php if(isset($item['dropdown'])){ ?>
<ul class="dropdown-menu" role="menu">
<div class="container">
<div class="row">
<ul class="col-sm-3">
<?php foreach($item['dropdown'] as $subitem) { ?>
<li><?php echo $subitem['title'] ?></li>
<?php }; ?>
</ul>
</div>
</div>
</ul>
<?php }; ?>
</li>
<?php }; ?>
</ul>
</div>
WHats the way to achieve that?
Maybe should I use For loop instead of foreach? I dont know..
Any feedback?
<div class="collapse navbar-collapse btnCollapse">
<ul class="nav navbar-nav">
<li>Home</li>
<?php foreach ($navItems as $item) { ?>
<li class="dropdown">
<?php echo $item['title']; ?><span class="caret"></span>
<?php if(isset($item['dropdown'])){ ?>
<ul class="dropdown-menu" role="menu">
<div class="container">
<div class="row">
<?php $i = 0; foreach($item['dropdown'] as $subitem) {
if($i%4==0){
echo "<ul class="col-sm-3">";
} ?>
<li><?php echo $subitem['title'] ?></li>
<?php if($i%4==3){
echo "</ul>";
}
$i++;
}; ?>
</div>
</div>
</ul>
<?php }; ?>
</li>
<?php }; ?>
</ul>
</div>
In your desired output you need 4 colums, so I devided menu items by 4 to put column i.e. if($i%4==0) for starting <ul> and if($i%4==3) for ending </ul>.

Php Sub Category loop html

I get the data from the database. but I can not write between li,ul html tags.There is a problem in the loop. How do I write between li ul categories and subcategories. I have this pdo mysql category function.
<?php
...
function kategoriVer($ustid=0){
$result = DB::get('SELECT * FROM urunler_kategori WHERE kategori_k='.$ustid.'');
echo '<ul class="drop-down">';
foreach($result as $kategori){
echo '<li class="drop">
'.$kategori->baslik_k.'';
kategoriVer($kategori->id_k);
}
echo '</li></ul>';
}
kategoriVer();
?>
output html:
<ul class="sub-menu">
<li class="menuparent">
Çadırlar
<ul class="sub-menu">
<li class="menuparent">Hi-Tech Çadırlar<ul class="sub-menu"></li></ul>
<li class="menuparent">Çelik Konstrüksiyon<ul class="sub-menu"></li></ul>
<li class="menuparent">Tribün Çadırlar<ul class="sub-menu"></li></ul>
<li class="menuparent">Yürüyüş Yolları<ul class="sub-menu"></li></ul>
</li>
</ul>
<li class="menuparent">Şemsiyeler<ul class="sub-menu"></li></ul>
<li class="menuparent">İklimlendirme<ul class="sub-menu"></li></ul>
</li>
</ul>
i want this output:
<ul class="sub-menu">
<li class="menuparent">
Headers
<ul class="sub-menu">
<li>Standard</li>
<li>No Topbar</li>
<li>Social Icons</li>
<li>Minimal</li>
<li>Classic</li>
</ul>
</li>
</ul>

Generating divs in php?

Say I have the following div:
<div id="nav">
<ul>
<li class="navButton">Home</li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Bodies</a></li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Pickguards</a></li>
<li class="navButton">Contact Us</li>
</ul>
</div>
I would want this to be repeated a certain number of times so the resulting html would look like:
<div id="nav">
<ul>
<li class="navButton">Home</li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Bodies</a></li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Pickguards</a></li>
<li class="navButton">Contact Us</li>
</ul>
</div> <div id="nav">
<ul>
<li class="navButton">Home</li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Bodies</a></li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Pickguards</a></li>
<li class="navButton">Contact Us</li>
</ul>
</div> <div id="nav">
<ul>
<li class="navButton">Home</li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Bodies</a></li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Pickguards</a></li>
<li class="navButton">Contact Us</li>
</ul>
</div>
If the number was 3. What php command is used to do this sort of thing? (I know I use a for loop, but I mean the code in between)
Essentially what I will eventually have is something like this:
for each product
div product
text from product file
close div product
Thanks
Just use the foreach or while like this:
foreach($array as $value){
?>
<div>
whatever <?php other php here ?>
</div>
<?php
}
<div class='nav'>
<ul>
<?php foreach ($products as $product): ?>
<li class='navbutton'><?php echo $product->text; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
if you have multiple different divs, make a foreach loop for that too, if you want same div to repeat 3 times, wrap it around a for loop
<?
for ($results as $value) {
echo '<div id="nav">';
echo ' <ul>';
echo ' <li class="navButton">Home</li>';
echo ' <li class="navButton">'.$value['name1'].'</li>';
echo ' <li class="navButton">'.$value['name2'].'</li>';
echo ' <li class="navButton">Contact Us</li>';
echo ' </ul>';
echo ' </div>';
}
?>

formatting help with wp_list_pages()

I posted this question on the wordpress forum but got no hits. Perhaps one of you might be able to point me in the right direction.
I am putting together a wp theme for a site I am working on. I want to get the layout to match the rest of the site as closely as possible and am running into trouble using the wp_list_pages/categories/bookmarks/etc() methods. I read through the documentation, but really don't see how to translate that into something that will work for me.
Calling the function with no args I get:
<li class="pagenav">Pages
<ul>
<li class="page_item page-item-2">About</li>
<li class="page_item page-item-5">Parent 1
<ul>
<li class="page_item page-item-10">Child 1
<ul>
<li class="page_item page-item-26">Grandchild 1</li>
</ul>
</li>
<li class="page_item page-item-16">Child 2</li>
</ul>
</li>
<li class="page_item page-item-7">Parent 2
<ul>
<li class="page_item page-item-22">Child 3</li>
<li class="page_item page-item-24">Child 4</li>
</ul>
</li>
<li class="page_item page-item-14">Parent 3
<ul>
<li class="page_item page-item-18">Child 5</li>
<li class="page_item page-item-20">Child 6</li>
</ul>
</li>
</ul>
</li>
Whereas I would like something more like:
<div class="nav-link">Pages
<div id="Pages_children">
<div class="nav-link">About</div>
<div class="nav-link">Parent 1
<div id="Parent 1_children">
<div class="nav-link">Child 1
<div id="Child 1_children">
<div class="nav-link">Grandchild 1</div>
</div>
</div>
<div class="nav-link">Child 2</div>
</div>
</div>
<div class="nav-link">Parent 2
<div id="Parent 2_children">
<div class="nav-link">Child 3</div>
<div class="nav-link">Child 4</div>
</div>
</div>
<div class="nav-link">Parent 3
<div id="Parent 3_children">
<div class="nav-link">Child 5</div>
<div class="nav-link">Child 6</div>
</div>
</div>
</div>
</div>
Is there a way for me to accomplish that with the args system? If not, is it possible for me to request an array from wp_list_TYPE() with the links and titles?
Is there a better way entirely to go about doing something like this?
Try looking at get_posts, which returns an array instead. Then you can loop through the array and print whatever you want from it.
For example:
<?php $posts = get_posts("numberposts=5&order=DESC&orderby=date"); ?>
<h5>Latest posts</h5>
<?php foreach($posts as $post): ?>
<?php setup_postdata($post); ?>
<div class="content">
<a class="title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span style="float:right" class="date"><?php the_time(__('F jS, Y', 'inove')); ?></span>
</div>
<?php endforeach; ?>

Categories