I have this most annoying problem; I'm trying to arrange three divs on a row, and then new row, and another three divs and so on, like this:
<div class="container">
<div class="row">
<div class="col-sm-1">1</div>
<div class="col-sm-1">2</div>
<div class="col-sm-1">3</div>
</div>
<div class="row">
<div class="col-sm-1">4</div>
<div class="col-sm-1">5</div>
<div class="col-sm-1">6</div>
</div>
</div>
As for this accepted answer,
There is one catch: 0 % 3 is equal to 0. This could result in
unexpected results if your counter starts at 0.
So how would i implement this into this code:
<div class="col-md-8">
<?php
foreach($this->movies->movie_data as $key => $movie){
$string = file_get_contents("http://example.com/?t=" . urlencode($movie->movie_titel). "&y=&plot=short&r=json");
$result = json_decode($string);
if($result->Response == 'True'){
?>
<div class="col-sm-4">
<?php if($result->Poster == 'N/A') : ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<?php else: ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo $result->Poster; ?>" class="img-responsive img-thumbnail"></a>
<?php endif; ?>
<div><b><?php echo $result->Title; ?></b></div>
<div><i><?php // echo $result->Plot; ?></i></div>
</div>
<?php }else{ ?>
<div class="col-sm-4">
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<div><b><?php echo $movie->movie_titel ?></b></div>
<div class="plot"><i><?php //echo 'N/A' ?></i></div>
</div>
<?php }}} ?
</div>
For some reason, divs is arranged like this:
My question: How do I arrange thumbnails on a new row, every third time?
Found the answer in the other Q... Didn't read, sorry about that.
<?php }
if (($key + 1) % 3 == 0) { ?>
</div>
<?php }
}} ?>
Related
I have a problem looping my html tags. My goal is to enclose every 4 div with class "item" inside the class of "item-wrap". So far here's my code:
$speakers will return 8 rows so "item-wrap" class will be display twice with 4 "item" class inside
<?php
$speaker_ctr = 0;
if(count($speakers) > 0){
?>
<div class="item-wrap">
<?php foreach($speakers as $speaker){ ?>
<div class="item"> <img class="lazy" data-lazy-src="<?php echo $speaker['imagepath']; ?>" />
<h5 class="txt-18 bold-font text-uppercase no-mbt mt-20"><?php echo $speaker['name']; ?></h3>
<p class="no-mn"><?php echo $speaker['position']; ?></p>
<?php echo $speaker['company']; ?>
</div>
<?php } ?>
</div>
<?php
$speaker_ctr++;
}
?>
Try below code:-
<?php
if(count($speakers) > 0){
for($i=0;$i<=count($speakers);$i++){
if($i%4==0){
echo '<div class="item-wrap">';
}
?>
<div class="item"> <img class="lazy" data-lazy-src="<?php echo $speakers[$i]['imagepath']; ?>" />
<h5 class="txt-18 bold-font text-uppercase no-mbt mt-20"><?php echo $speakers[$i]['name']; ?></h3>
<p class="no-mn"><?php echo $speakers[$i]['position']; ?></p>
<?php echo $speakers[$i]['company']; ?>
</div>
<?php
if($i%4==0){
echo '</div>';
}
}
}
Try with -
$speaker_ctr = 0;
if(count($speakers) > 0){
?>
<div class="item-wrap">
<?php
foreach($speakers as $speaker){
$speaker_ctr++; // increment
?>
<div class="item"> <img class="lazy" data-lazy-src="<?php echo $speaker['imagepath']; ?>" />
<h5 class="txt-18 bold-font text-uppercase no-mbt mt-20"><?php echo $speaker['name']; ?></h3>
<p class="no-mn"><?php echo $speaker['position']; ?></p>
<?php echo $speaker['company']; ?>
</div>
<?php
// print if divisible by 4
// every 4th element
if($speaker_ctr%4 == 0 && $speaker_ctr != count($speakers)) {
echo "</div><div class='item-wrap'>";
}
}
?>
</div>
<?php
}
quick question, i want to link the BLOCK1 to another page. Is it possible? do anyone got a solution? i have tried abit and my brain is going mad T_T. there are 5 other blocks that i which to link to other pages aswell.
this is the code below:
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>
</div>
<?php } ?>
<!--BLOCK1 END-->
Just put a <a>-Tag arount the block you want to link:
<a href="'your link here'"> <!-- start link here -->
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>
</a> <!-- end link here -->
Or put it around any other part you want to have the link on. It's just basic HTML and has nothing to do with PHP.
here is the fullcode of the block. i missed to copy the top of it:
<?php if ((!empty ($optimizer['block1_text_id'])) || (!empty ($optimizer['block1_textarea_id'])) ) { ?>
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>
You can use with this JS
<div class="midrow_block axn_block1" onclick="location.href='url'">content</div>
jQuery:
$("div").click(function(){
window.location=$(this).find("a").attr("href"); return false;
});
I've got this PHP code:
<div class="connect_wrap <?php echo $this->class; ?> block" <?php echo $this->cssID; ?>>
<?php if(!$this->empty): ?>
<?php foreach($this->entries as $entry): ?>
<div class="entry block <?php echo $entry->class; ?>">
<div class="tab">
<ul class="tabs">
<li class="tab-link current" data-tab="Kunden">Kunden</li>
<li class="tab-link" data-tab="Loesungen">Lösungen</li>
</ul>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM kunden WHERE partner=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Kunden" class="tab-content current">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/kunden-detail/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM solutions WHERE solution_provider=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Loesungen" class="tab-content">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/synaptic-commerce-solution/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
In that code, I've got two DB queries. My problem is, if there is no data for both queries, the div with the class "connect_wrap" should not be displayed.
How can I do that?
Thanks in advance.
do you want to check if the query has data in it and its not empty ? if so try num_rows it will return the number of rows that the query found/affected for example to check if th query returned one or more rows
if($result->num_rows >= 1) {
//do stuf
} else {
// no result found
}
Move the query execution up or preferably: not within the html but in a different file/class. Then add a check before the content_wrap div: if($kundenResult->num_rows >= 1 || $solutionsResult->num_rows >= 1). If you just keep the individual checks like you already have, it will only show the content_wrap div if either or both of the queries return rows of data.
//In PHP fetch content and truncate the string or variable, till 3rd breakline then display
//when i use this method the entire div deallocated and the its not displaying properly...hope the fetch content contain some image tags too // ...
<div class="mid-blks-cont">
<!-- Block1 -->
<div class="mid-block-1 boxgrid caption">
<?php
foreach ($querypost as $row) {
$content = $row->post_content;
$pcontent_overview = (strlen($content) > 300) ? substr($content,0,300).'... Read More' : $content;
if($img == "No Image Uploaded" ) {
?>
<img alt="" src="<?php echo base_url(); ?>assets/img/samples/sample1.jpg"style="width: 391px; height:231px"/>
<?php } else { ?>
<img alt="" src="<?php echo base_url(); ?>uploads/<?php echo $row->post_media ;?>" style="width: 391px; height:231px" />
<?php }?>
<h4 class="cat-label cat-label2"><?php echo $row->category;?></h4>
<div class="cover boxcaption">
<h3><?php echo $row->post_title;?><span class="topic-icn"><?php echo $row->comment_count;?></span></h3>
<p> <?php echo $pcontent_overview;?>....</p>
MORE <i class="fa fa-angle-double-right"></i>
</div>
<?php } ?>
</div>
</div>
so i guess this is pretty easy for most of you, but i can't figure this out.
im trying to make the links dynamic eg: href="linkname(#1 or #2 etc)"
any ideas?
<?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
<?php foreach ($top_fundraisers as $index => $fundraiser): ?>
<a title="" class="fancybox" href="linkname(GENERATE CODE HERE)">
<div class="top-fundraiser">
<div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
<img src="<?php
if($fundraiser['member_pic_medium']) {
print htmlentities($fundraiser['member_pic_medium']);
} else {
print $template_dir . '/images/portrait_placeholder.png';
}
?>"/>
</div>
</div>
</a>
<?php endforeach;?>
<?php endif; ?>
Suppose below is what you need.
<?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
<?php foreach ($top_fundraisers as $index => $fundraiser): ?>
<a title="" class="fancybox" href="linkname(#<?php echo $index + 1; ?>)">
<div class="top-fundraiser">
<div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
<img src="<?php
if($fundraiser['member_pic_medium']) {
print htmlentities($fundraiser['member_pic_medium']);
} else {
print $template_dir . '/images/portrait_placeholder.png';
}
?>"/>
</div>
</div>
</a>
<?php endforeach;?>
<?php endif; ?>