When I click different product categories,I cannot get the corresponding product items, but only the items of the active category is displayed.
When I click another nav-item the previously displayed items remain unchanged i.e, unable to change the class " show active" in the tab-panes
Code:
<?php
$this->load->view ( 'templates/header' );
?>
<section class="container">
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
<?php $flag = 0; foreach ( $gallery_category as $gallery_category_data ) {?>
<li class="nav-item">
<a class="nav-link <?php if($flag==0){echo 'active';$flag ++;}?>"
id="pills<?php echo $gallery_category_data['gallery_category_id'];?>"
data-toggle="pill" href="#<?php echo $gallery_category_data['gallery_category_id'];?>"
role="tab" aria-controls="pill<?php echo $gallery_category_data['gallery_category_id'];?>"
aria-selected="<?php if($flag==0){echo 'true';}?>"><?php echo $gallery_category_data['gallery_category_name'];?></a>
</li>
<?php }?>
</ul>
<div class="tab-content" id="pills-tabContent">
<?php $counter=0; foreach ( $gallery_category as $gallery_category_data ) {?>
<div class="tab-pane fade <?php if($counter==0){echo 'show active';}?>" id="<?php echo $gallery_category_data['gallery_category_id'];?>" role="tabpanel" aria-labelledby="pills<?php echo $gallery_category_data['gallery_category_id'];?>">
<h6><?php echo $gallery_category_data['gallery_category_name']; ?></h6>
<div class="row">
<?php foreach ( $gallery_category_data ['gallery_item'] as $gallery_item_data ) {?>
<div class="col-md-3 mb-3">
<figure>
<img src="<?php echo base_url();?>assets/img/products/<?php echo $gallery_item_data['gallery_image']; ?>" class="img-fluid">
<a href="product_details.php">
<figcaption class="text-center">
<h6 class="mt-3">Saree</h6>
<p class="text-muted"><strong>Rs. 799 /-</strong></p>
</figcaption>
</a>
</figure>
</div>
<?php }?>
</div>
</div>
<?php $counter++; }?>
</div>
</section>
<?php
$this->load->view ( 'templates/footer' );
?>
I cannot diagnose the problem in this code, Please help me out from this problem
if you replace:
<?php if($flag==0){echo 'active';$flag ++;}?>
by
<?php if($flag==0){echo 'nav'.$flag;$flag ++;}?>
and delete:
<?php if($counter==0){echo 'show active';}?>
After your script add this
<script>
$(document).ready(function(){
$( ".nav0" ).trigger( "click" );
});
</script>
its good ?
Just match the condition inside a foreach loop:
$cat = $gallery_category_data['gallery_category_name'];
foreach ( $gallery_category_data ['gallery_item'] as $gallery_item_data )
{
if($gallery_item_data['category name in table'] == $cat){
}
}
Related
I wish to put a drop-down button on my WordPress category page. This drop-down button will have two choices; 'Ascending' and 'Descending'. After clicking the choice, posts on that page will re-order accordingly.
Can anyone help? Right now, the theme is using years. But it doesn't work properly.
Below, the theme is displaying post years in a drop-down menü.
<li class="dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Sırala</a>
<ul class="dropdown-menu">
<?php
$terms_year = array(
'post_type' => array('post'),
);
$years = array();
$query_year = new WP_Query( $terms_year );
if ( $query_year->have_posts() ) :
while ( $query_year->have_posts() ) : $query_year->the_post();
$year = get_the_date('Y');
if(!in_array($year, $years)){
$years[] = $year;
}
endwhile;
wp_reset_postdata();
endif;
foreach ($years as $year) {
?>
<li class="nav-item"><a class="nav-link dropdown-item" data-bs-toggle="tab" data-bs-target="#year-<?php echo $year; ?>" type="button" role="tab"><?php echo $year; ?></a></li>
<?php } ?>
</ul>
</li>
I want to change that, as I have mentioned.
And here is how posts are displayed (but it doesn't work).
<?php
foreach( $years as $year ) {
?>
<div class="tab-pane fade" id="year-<?php echo $year; ?>">
<div class="items">
<div class="container">
<div class="row">
<?php wp_reset_query(); if (have_posts()) : while (have_posts()) : the_post(); $date = get_the_date('Y'); ?>
<?php if($date == $year) { ?>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-4 column">
<div class="item">
<a href="<?php the_permalink(); ?>" style="color: <?php echo $rl_category_color; ?>;" class="d-flex align-items-center">
<div class="in">
<div class="d-flex justify-content-between author">
<div class="author-name col-7">
<?php
$author = get_post_meta( get_the_ID(), 'postAuthor', true );
if(!empty($author)) {
foreach ($author as $author_item => $item) {
echo get_the_title($item).'<br>';
}
}
?>
</div>
<div class="rank col-5 text-end">
<?php
$konu = get_the_category( get_the_ID() );
foreach ($konu as $item) {
$konu_name = $item->name;
}
echo $konu_name;
?>
</div>
</div>
<div class="title"><?php echo title_limit(40); ?></div>
<p><?php echo icerik_limit(get_the_content(), 150); ?></p>
</div>
</a>
</div>
</div>
<?php } ?>
<?php endwhile; endif; ?>
</div>
</div>
</div>
</div>
<?php } ?>
Related Page: https://www.mgc.com.tr/haberler/
image
I want to display slide with two records at a time. Now I am only getting only one record at a time in slider because I fetch data in while loop. My code is:
<ul class="slides">
<?php
...
while($eventData = mysql_fetch_array($eventSql))
{
?>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<?php } ?>
</ul>
You can add a counter and open/close the list item only every second iteration:
<ul class="slides">
<li class="questions-slide-item">
<?php
...
$count = 0;
while($eventData = mysql_fetch_array($eventSql))
{
if($count > 0 && $count % 2 == 0) {
?>
</li>
<li class="questions-slide-item">
<?php
}
?>
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
<?php
$count++;
}
?>
</li>
</ul>
You can first take all the rows in one array and then use that array as per your needs.
See to following code to understand what I am trying to say.
<?php
...
$eventData= array();
while($row = mysql_fetch_assoc($eventSql))
{
$eventData [] = $row;
}
for($i=0;count($eventData);$i=$i+2)
{
?>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData[$i]['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData[$i+1]['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<?php } ?>
I have a bunch of thumbnails that are loaded through several Advanced Custom Fields repeater fields. When clicking the thumbnail I want the respective text to each thumbnail to appear in the Bootstrap tab's content div. The text is in the same repeater as the image, but a seperate field. But I don't know how to access the respective repeater fields text with the click. The number of thumbnails is infinite.
The list of thumbnails use this code:
<ul>
<?php foreach (get_field('repeater-field', 39) as $row) :?>
<li> <img class="img-responsive img-rounded img-ref" src="<?php print $row['image'] ?>"/> </li>
<?php endforeach; ?>
</ul>
And this is what I have so far for the tab content but it will only show the first repeater field and not the text for every respective thumbnail:
<div class="tab-content">
<div class="tab-pane active" id="home"></div>
<div class="tab-pane" id="profile">
<?php
$rows = get_field('repeater-field', 39);
echo $rows[0]['text'];
?>
</div>
</div>
Managed to solve it myself kinda. But the Bootstrap fade effects disappears for some reason…
Used this for the thumbnails:
<ul class="tabs">
<?php
$i = 1;
while( have_rows('my_field', 39) ): the_row();
// vars
$image = get_sub_field('thumb');
?>
<li class="tab-list">
<a href="#<?php echo $i; ?>" data-toggle="tab">
<img class="img-responsive img-rounded img-ref" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
</a>
</li>
<?php
$i++;
endwhile;
?>
</ul>
<?php endif; ?>
And this for the tabs:
<div class="tab-content">
<div class="tab-pane fade in " id="home"></div>
<?php
$i = 1;
while( have_rows('my_field', 39) ): the_row();
// vars
$text = get_sub_field('my_text');
?>
<div class="tab-pane fade" id="<?php echo $i; ?>">
<?php echo $text; ?>
</div>
<?php
$i++;
endwhile;
?>
</div>
<?php endif; ?>
Im trying to learn PHP and using it with the Bootstrap library for my site. I am looking to use the bootstrap carousel as seen here
What I am trying to achieve is the carousel with captions and the Machine Name I am showing in the picture would be a hyperlink that will take you to that page for more info. I have a MySQL database that contains the machine name and the ImagePath as to where it is located.
So my code currently is as below -
<?php
while($row = mysql_fetch_array($result))
{
?>
<div class="bs-example">
<div id="carousel-example-captions" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-captions" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-captions" data-slide-to="1"></li>
<li data-target="#carousel-example-captions" data-slide-to="2"></li>
</ol>
<img data-src="holder.js/900x800/auto/#777:#777" style="height: 400px; width: 400px;" alt="First slide image" src="<?php echo $row['MachineImagePath'] ?>"/>
<div class="finlay-carousel-caption">
<h3><?php echo $row['MachineName']?></h3>
<div>
<p>
Click the link above for more details about <?php echo $row['MachineName']>
</p>
</div>
<a class="left carousel-control" href="#carousel-example-captions" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-captions" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>
<?php
}
mysql_close($connection);
?>
Currently instead of placing each image inside the carosuel this is creating a new carousel for each image down the page. Should the <carousel-example-captions> html be outside the while loop so it is created once and then the img tag will pick up the new image for each slide as you click the next > and prev < buttons.
Note also - <h3><?php echo $row['MachineName']?></h3> - I have not yet turned the header into a hyperlink as I wanted to get the carousel working correctly first.
I recently added a carousel with a link from the mysql database. The issue is that you have the create new carousel code inside of the while statement. If you take it out and just have the new slide commands inside the while it will work perfect.
<div class="bs-example">
<div id="carousel-example-captions" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php
$counter = 1;
while($row = mysql_fetch_array($result)){
?>
<div class="item<?php if($counter <= 1){echo " active"; } ?>">
<a href="">
<img data-src="holder.js/900x800/auto/#777:#777" style="height: 400px; width: 400px;" alt="First slide image" src="<?php echo $row['MachineImagePath'] ?>"/>
</a>
<div class="finlay-carousel-caption">
<h3><?php echo $row['MachineName']?></h3>
<p>Click the link above for more details about <?php echo $row['MachineName']>; ?></p>
</div>
</div>
<?php
$counter++;
}
mysql_close($connection);
?>
<ol class="carousel-indicators">
<li data-target="#carousel-example-captions" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-captions" data-slide-to="1"></li>
<li data-target="#carousel-example-captions" data-slide-to="2"></li>
</ol>
</div>
</div>
If you get the number of rows from you mysql statement you can change the indicators section to have a loop that would allow for unlimited number of slides.
I've solved this issue creating a control variable like this:
define a control variable: $active = true
create a loop
check inside a loop if $active is true
set control variable to false after loop ends
<?php $active = true; ?>
<?php foreach($images as $image):?>
<div class="carousel-item <?php echo ($active == true)?"active":"" ?>">
<img src="assets/img/anuncios/<?php echo $image['image'] ?>" class="d-block w-100" alt="...">
</div>
<?php $active = false; ?>
<?php endforeach; ?>
This way, the active class is printed only at the first loop.
I find most carousel software, even that based on JQuery, too complicated to configure and maintain, that's why I created my own carousel that you can download here for free: https://33hops.com/php-html5-lightweight-slideshow-carousel.html
The premises on top of which I programmed this are short and straight: I just wanted something that could automatically pick the images put in a given folder, preload them and cycle through them with a nice HTML5 transition effect and optionally texts overlayed on top. The result is an ultralight PHP carousel with an ultra low footprint ideal for mobile developments and easy maintenance, just change the images and reload.
<div id="carousel-example-generic" class="carousel slide clearfix" data-ride="carousel">
<div class="carousel-inner">
<?php
$tmp_post = $post;
$query_args = array( 'suppress_filters' => false, 'post_type' => 'post' );
$slides = get_posts( $query_args );
if ( ! empty( $slides ) ) {
$counter = 0;
foreach( $slides as $post ) { setup_postdata( $post ); $counter++;
?>
<div class="item<?php if ($counter == 1) echo ' active'; ?>">
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($loop->ID) );?>
<img src="<?php echo $feat_image ?>" class="img-responsive img-circle"/>
<div class="finlay-carousel-caption">
<?php $degisc= get_post_meta( $post->ID, '_my_meta_value_key', true );?>
<h1><?php echo $degisc;?></h1>
<?php $position = get_post_meta( $post->ID, '_my_meta_value_key1', true );?>
<p><?php echo $position;?></p>
<div class="line marginBottom15"></div>
<?php $words = get_post_meta( $post->ID, '_my_meta_value_key2', true );?>
<p><?php echo $words;?></p>
<div class="line"></div>
</div>
</div>
<?php } }
$post = $tmp_post;
?>
</div>
</div>
geeks please help,
I have a problem with the usage of array keys with the while loop.
I'm trying to display the twitter bootstrap slider images by looping from the database with this code:
<div id="slider">
<!--Code for make home images slide show-->
<div id="myCarousel" class="carousel slide">
<!-- here comes the engine to run the sliders -->
<?php
$query = 'SELECT * FROM banners WHERE status = 1 ORDER BY id ASC';
?>
<div class="carousel-inner">
<?php
if ($r = mysql_query($query , $conn)) { //run the query
$row = mysql_fetch_array($r);
reset($row);
while (list($key, $value) = each($row)) {
if ($key == 0) { ?>
<div class="item active">
<img src="images/homeimages/<?php echo $value['image'];?>" alt="<?php echo $value['title'];?>">
<!-- <img src="images/homeimages/one.jpg" alt=""> -->
<div class="carousel-caption">
<!-- <h4>First Thumbnail label</h4> -->
<p><i><?php echo $value['title'];?></i></p>
</div>
</div>
<?php }else{ ?>
<div class="item">
<img src="images/homeimages/<?php echo $value['image'];?>" alt="<?php echo $value['title'];?>">
<!-- <img src="images/homeimages/one.jpg" alt=""> -->
<div class="carousel-caption">
<!-- <h4>First Thumbnail label</h4> -->
<p><i><?php echo $value['title'];?></i></p>
</div>
</div>
<?php }
}
}else {
print '<p style="color: red;">Could not retrieve the slider:<br />' . mysql_error($dbc) . '.</p>';
} ?>
</div>
<!-- <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a> -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
</div>
</div><!-- endof slider -->`
.
as`it's well known the first slider image of twitter bootstrap must have the class of active to make sure it loads faster. I need to pick the first slider image from an array and add the class of active into it while the rest of the slider images remains the same without an active class.
can someone please tell me where i'm messing up with my codes?
Try this:
<div class="carousel-inner">
<?php
if ($r = mysql_query($query , $conn)) {
$count = 0;
while ($row = mysql_fetch_array($r){
if ($count == 0){?>
<div class="item active">
<?php}
else { ?>
<div class="item">
<?php}?>
<img src="images/homeimages/<?php echo $row['image'];?>" alt="<?php echo $row['title'];?>">
<div class="carousel-caption">
<p><i><?php echo $row['title'];?></i></p>
</div>
</div>
<?php
}
$count ++;
}
}
else {
print '<p style="color: red;">Could not retrieve the slider:<br />' . mysql_error($dbc) . '.</p>';
}