Image height not working on php loop - php

Here's the div that manages the look of each item in the loop:
<div style="float:left;width:30%;padding:30px;height:auto;">
<img src="<?php echo $r['image']['sizes']['team']; ?>" style="max-width:750px !important;width:100%;">
<h3>
<?php echo $r['name']; ?>
</h3>
<div class="position">
<?php echo $r['position']; ?>
</div>
<?php echo $r['intro_text']; ?>
<?php if ($r['learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r['learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name']); ?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name']; ?></h3>
<div class="position">
<?php echo $r['position']; ?>
</div>
<div class="content">
<?php echo $r['learn_more_text']; ?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
</div>
If I set the height to a fixed number (eg: 450x), the images are aligned in a row. But that will make the page non mobile responsive. If I set the height to auto or to a percentage like 30%, the images become mobile responsive but they don't align. I get 2 images that separate into different rows.
Also, I got 2 sections of image. One is called Our Leadership and the other is called Our Team. The section at the bottom is aligned correctly and is contained in a div. The div above it refuses to be contained in a div. If I wrap it in a div, Only the first item wraps itself in the div. I've no idea why.
eg:
<center>
<div>
<div>first item here</div>
</div>
<div>second item here</div>
<div>third item here</div>
<div>fourth item here</div>
Here's the complete code for both sections:
<center><h2>Our Leadership</h2></center>
<center><div>
<?php
$people = get_field('people');
$a = 0;
foreach ($people as $r) {
$a++;
?>
<div style="float:left;width:30%;padding:30px;height:auto;">
<img src="<?php echo $r['image']['sizes']['team']; ?>" style="max-width:750px !important;width:100%;">
<h3>
<?php echo $r['name']; ?>
</h3>
<div class="position">
<?php echo $r['position']; ?>
</div>
<?php echo $r['intro_text']; ?>
<?php if ($r['learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r['learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name']); ?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name']; ?></h3>
<div class="position">
<?php echo $r['position']; ?>
</div>
<div class="content">
<?php echo $r['learn_more_text']; ?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div></center>
<div style="clear:both;"></div>
<center><h2>Our Team</h2></center>
<center><div>
<?php
$people2 = get_field('people_bottomsection');
$a = 0;
foreach ($people2 as $r) {
$a++;
?>
<div style="float:left;width:30%;padding:30px;height:auto;">
<img src="<?php echo $r['image']['sizes']['team']; ?>" style="max-width:750px !important;width:100%;">
<h3>
<?php echo $r['name']; ?>
</h3>
<div class="position">
<?php echo $r['position']; ?>
</div>
<?php echo $r['intro_text']; ?>
<?php if ($r['learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r['learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name']); ?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name']; ?></h3>
<div class="position">
<?php echo $r['position']; ?>
</div>
<div class="content">
<?php echo $r['learn_more_text']; ?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div></center>
<div style="clear:both;"></div>
Check out the source code at: http://www.equitasmg.com/who-we-are-2/

it's because the items in the loop are having different height. So, try adding a constant height to each item in the loop.
Eg:
<div style="float:left;width:30%;padding:30px;min-height:550px;"></div>

Related

PHP Loop executing on top of each other

It should be like this:
<div> code here </div>
<div> code here </div>
<div> code here </div>
Each div looping right after the other. Instead, it is executing like this:
<div> code here </div>
<div> code here </div>
<div> code here </div>
Page I am working on: http://www.equitasmg.com/who-we-are-2/
The images are not aligned (should be in a row).
Here's the PHP:
<center><h2>Our Leadership</h2></center>
<?php
$people= get_field('people');
$a=0;
foreach ($people as $r) {
$a++;
?>
<div style="float:left;width:30%;padding:30px;">
<img src="<?php echo $r['image']['sizes']['team'];?>" style="max-width:750px !important;width:250px;">
<h3>
<?php echo $r['name'];?>
</h3>
<div class="position">
<?php echo $r['position'];?>
</div>
<?php echo $r['intro_text'];?>
<?php if ($r[ 'learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r[ 'learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name'] );?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name'];?></h3>
<div class="position">
<?php echo $r['position'];?>
</div>
<div class="content">
<?php echo $r['learn_more_text'];?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
</div>
<?php } ?>
<?php } ?>
Here is the problem one div should between closing php tag
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
<?php } ?>
</div>
<?php } ?>
You don't need to float every div in loop just add a div before loop and float that div to left.
remove floating Style within loop.. here is your clean code.
JS BIN
<div style="float:left;width:30%;padding:30px;">
<?php
$people= get_field('people');
$a=0;
foreach ($people as $r) {
$a++;
?>
<div style="">
<img src="<?php echo $r['image']['sizes']['team'];?>" style="max-width:750px !important;width:250px;">
<h3>
<?php echo $r['name'];?>
</h3>
<div class="position">
<?php echo $r['position'];?>
</div>
<?php echo $r['intro_text'];?>
<?php if ($r[ 'learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r[ 'learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name'] );?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name'];?></h3>
<div class="position">
<?php echo $r['position'];?>
</div>
<div class="content">
<?php echo $r['learn_more_text'];?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
</div>
<?php } ?>
<?php } ?>
<div style="clear:both;"></div>
</div>

Div not wrapping around all items in a loop

I got 2 sections on a page. You can see it here: http://www.equitasmg.com/who-we-are-2/
Both sections have a <div> wrapped around them, but the first section "Our Leadership" seems to not like the <div>. The <div> wraps around the first item in the section but does not wrap around all the items.
Here is the PHP for both sections.
First section
<center><h2>Our Leadership</h2></center>
<center><div>
<?php
$people= get_field('people');
$a=0;
foreach ($people as $r) {
$a++;
?>
<div class="people">
<img src="<?php echo $r['image']['sizes']['team'];?>" style="max-width:750px !important;width:100%;">
<h3>
<?php echo $r['name'];?>
</h3>
<div class="position">
<h4><?php echo $r['position'];?></h4>
</div>
<?php echo $r['intro_text'];?>
<?php if ($r[ 'learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r[ 'learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name'] );?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name'];?></h3>
<div class="position">
<?php echo $r['position'];?>
</div>
<div class="content">
<?php echo $r['learn_more_text'];?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div></center>
<div style="clear:both;"></div>
Second section
<center><h2>Our Team</h2></center>
<center><div>
<?php
$people2= get_field('people_bottomsection');
$a=0;
foreach ($people2 as $r) {
$a++;
?>
<div class="people">
<img src="<?php echo $r['image']['sizes']['team'];?>" style="max-width:750px !important;width:100%;">
<h3>
<?php echo $r['name'];?>
</h3>
<div class="position">
<h4><?php echo $r['position'];?></h4>
</div>
<?php echo $r['intro_text'];?>
<?php if ($r[ 'learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r[ 'learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name'] );?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name'];?></h3>
<div class="position">
<?php echo $r['position'];?>
</div>
<div class="content">
<?php echo $r['learn_more_text'];?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div></center>
<div style="clear:both;"></div>
You just got extra div.
First section you got extra div here
<center><h2>Our Leadership</h2></center>
<center>
<div>
<?php
$people= get_field('people');
$a=0;
foreach ($people as $r) {
$a++;
?>
<div class="people">
<img src="<?php echo $r['image']['sizes']['team'];?>" style="max-width:750px !important;width:100%;">
<h3>
<?php echo $r['name'];?>
</h3>
<div class="position">
<h4><?php echo $r['position'];?></h4>
</div>
<?php echo $r['intro_text'];?>
<?php if ($r[ 'learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r[ 'learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name'] );?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name'];?></h3>
<div class="position">
<?php echo $r['position'];?>
</div>
<div class="content">
<?php echo $r['learn_more_text'];?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
<!-- </div> --> //extra div here
<?php } ?>
</div>
<?php } ?> //end of foreach
</div>
</center>
<div style="clear:both;"></div>
second section
<center><h2>Our Team</h2></center>
<center>
<div>
<?php
$people2= get_field('people_bottomsection');
$a=0;
foreach ($people2 as $r) {
$a++;
?>
<div class="people">
<img src="<?php echo $r['image']['sizes']['team'];?>" style="max-width:750px !important;width:100%;">
<h3>
<?php echo $r['name'];?>
</h3>
<div class="position">
<h4><?php echo $r['position'];?></h4>
</div>
<?php echo $r['intro_text'];?>
<?php if ($r[ 'learn_more_text']) { ?>
Learn More
<?php } ?>
<?php if ($r[ 'learn_more_text']) { ?>
<div id="<?php echo sanitize_title($r['name'] );?>" class="reveal-modal medium" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h3><?php echo $r['name'];?></h3>
<div class="position">
<?php echo $r['position'];?>
</div>
<div class="content">
<?php echo $r['learn_more_text'];?>
</div>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
<!-- </div> --> //extra div
<?php } ?>
</div>
<?php } ?>
</div>
</center>

Search results form to show another page

I am using a Vebra plugin on Wordpress, they use shortcodes to show a search area and a shortcode to show the results.
I have my homepage (http://lytham.voodoodev4.co.uk/) using the "search" shortcode, my "properties" shortcode is on http://lytham.voodoodev4.co.uk/?page_id=33
When I search on the page it just refreshes the page, how do I push the search results to that page?
Search php:
<div id="propertyFilter" class="vp_search">
<form action="<?php echo vp_get_search_link()?>" method="GET">
<?php vp_hidden_fields(); ?>
<div class="property_refine">Refine your search:</div>
<div class="property_type">
<?php vp_get_areas(); ?>
</div>
<div class="property_search_group">
<p>Minimum number of bedrooms</p>
<?php vp_get_bedrooms(); ?>
</div>
<div class="property_search_group vp_price">
<p>Minimum price of property</p>
<?php vp_get_minprice(); ?>
</div>
<div class="property_search_group vp_price">
<p>Maximum price of property</p>
<?php vp_get_maxprice(); ?>
</div>
<div class="property_search_group vp_rent">
<p>Minimum rent for property</p>
<?php vp_get_minrent(); ?>
</div>
<div class="property_search_group vp_rent">
<p>Maximum rent for property</p>
<?php vp_get_maxrent(); ?>
</div>
<div class="property_search_group vp_commercial">
<p>Min Area (sqft)</p>
<?php vp_get_minarea(); ?>
</div>
<div class="property_search_group vp_commercial">
<p>Max Area (sqft)</p>
<?php vp_get_maxarea(); ?>
</div>
<div class="property_search_group">
<p>Type of property</p>
<?php vp_get_property_types(); ?>
</div>
<div class="property_search_group">
<p>Location</p>
<input type="text" id="vp_location" name="vp_location" placeholder="Enter postcode or place name" value="<?php vp_get_location(); ?>" />
</div>
<div class="property_search_group">
<p>Search</p>
<?php vp_get_radius(); ?>
</div>
<input class="submit" type="submit" value="Search" />
</form>
</div>
Properties results PHP:
<div id="propertyResults">
<?php echo vp_list_head();
if ($properties=vp_theproperties()) {
switch (vp_get_view()) {
case "list": ?>
<div id="propertyListView">
<div id="propertyOrdering" class="clearfix">
<div id="orderBy">
<span id="vp_order_message">Order by:</span>
<?php vp_get_orderby(); ?>
View Map
</div>
</div>
<div class="clearfix">
<?php foreach ($properties as $property) { ?>
<div class="property">
<div class="left_column">
<div class="property_image">
<a class="property_overview_thumb" href="<?php echo vp_propertyurl($property->vebraid); ?>" title="<?php echo $property->address_custom; ?>">
<?php echo vp_propertyimage($property->vebraid,0,"property_image"); ?>
</a>
<div class="property_tagline"><?php echo $property->web_status; ?></div>
</div>
</div>
<div class="right_column">
<div class="property_summary">
<h3 class="property_title">
<span><?php echo $property->address_custom; ?> <?php echo $property->property_type; ?></span>
</h3>
<h4 class="property_address"><?php echo $property->address_display; ?></h4>
<div class="property_excerpt"><?php echo $property->excerpt; ?></div>
</div>
</div>
<div class="property_features clearfix">
<?php if ($property->area == "Commercial") {
if (!empty($property->propertyarea_sqft)) {?>
<span class="property_area"><?php echo $property->propertyarea_sqft; ?> sqft</span>
<?php } ?>
<?php } else {?>
<span class="property_beds"><?php echo $property->bedrooms; ?> Bedrooms</span>
<span class="property_baths"><?php echo $property->bathrooms; ?> Bathrooms</span>
<?php } ?>
<div class="property_price">£<?php echo number_format($property->price,0,"",","); ?> <?php echo $property->price_postfix; ?>View Details<?php do_action('vp_other_action_buttons',$property->vebraid,'button property_button') ?></div>
</div>
</div>
<?php } ?>
</div>
<div class="properties-paging">
<ul>
<?php if (vp_current_page() > 1) { ?>
<li>< Previous</li>
<?php } ?>
<li>Page <?php echo vp_current_page(); ?> of <?php echo vp_page_count(); ?></li>
<?php if (vp_current_page() < vp_page_count()) { ?>
<li>> Next</li>
<?php } ?>
</ul>
</div>
</div>
<?php
break;
case "map":?>
<div id="propertyMapView">
<div id="propertyOrdering" class="clearfix">
<div id="orderBy">
View List
</div>
</div>
<?php vp_map_markers($properties); ?>
<div id="vp-map" style="width: 100%; height: 550px;"></div>
</div>
<?php
break;
case "featured": ?>
<?php foreach ($properties as $property) { ?>
<div class="property">
<div class="left_column">
<div class="property_tagline badge_<?php echo str_replace(" ","_",$property->web_status); ?>"></div>
<div class="property_image">
<a class="property_overview_thumb" href="<?php echo vp_propertyurl($property->vebraid); ?>" title="<?php echo $property->address_name; ?>">
<?php echo vp_propertyimage($property->vebraid,0,"property_image"); ?>
</a>
</div>
</div>
<div class="right_column">
<ul class="property_summary">
<li class="property_title">
<?php echo $property->address_custom; ?><span><?php echo $property->property_type; ?></span>
</li>
<li class="property_address"><?php echo $property->address_display; ?></li>
<li class="property_price">£<?php echo number_format($property->price,0,"",","); ?> <?php echo $property->price_postfix; ?></li>
</ul>
<div class="buttons clearfix">
View Details
</div>
</div>
</div>
<?php } ?>
<?php
break;
}
} else { ?>
<p>No matching properties found. Please try alternative search criteria.</p>
<?php } ?>
<?php echo vp_list_footer();?>
</div>
SOLVED:
In the vp-search.php I changed:
<form action="<?php echo vp_get_search_link()?>" method="GET">
to
<form action="<?php echo vp_get_search_link()?>/property-results/" method="GET">
Obviously replace /property-results/ for the page that has the properties shortcode in it :)

PHP affecting column layout

The structure of the main body of my page is constructed of three columns, these columns are generated by MYSQL data and then formulated in to three columns using PHP.
Below is PHP code and the layout which provides the three columns. The problem which I have is that if the data provides a layout two columns wide then everything is fine and it looks like this.
http://goo.gl/TDKI2J
However if the data provides a layout three columns wide then it looks like this.
http://goo.gl/0uqPvX
I think the problem is the div tag after the on the third column, but not sure of the best way to fix the issue.
Here is the code.
<?php $columnSelector = 0; // define a column selector ?>
<?php while($row = mysql_fetch_array($result)) :?>
<?php if ($columnSelector == 0): ?>
<div class="row-fluid">
<article class="span4 mid">
<div class="img">
<img src="images/<?php echo $row['image']; ?>" alt="post4" />
<div class="overlay"></div>
</div>
<div class="info">
<p class="tags">
<?php echo $row['event_type']; ?>
<?php echo $row['location']; ?>
</p>
<h1><?php echo $row['event_title']; ?></h1>
<p class="details"> | </p>
<p class="text">
<?php echo $row['event_details_short']; ?>
</p>
</div>
</article>
<?php elseif ($columnSelector == 1): ?>
<article class="span4 mid">
<div class="img">
<img src="images/<?php echo $row['image_link']; ?>" alt="post4" />
<div class="overlay"></div>
</div>
<div class="info">
<p class="tags">
<?php echo $row['event_type']; ?>
<?php echo $row['location']; ?>
</p>
<h1><?php echo $row['event_title']; ?></h1>
<p class="details"> <?php echo $row['date']; ?> | <?php echo $row['posted_by']; ?></p>
<p class="text">
<?php echo $row['event_details_short']; ?>
</p>
</div>
</article>
<?php elseif ($columnSelector == 2): ?>
<article class="span4 mid">
<div class="img">
<img src="images/<?php echo $row['image_link']; ?>" alt="post4" />
<div class="overlay"></div>
</div>
<div class="info">
<p class="tags">
<?php echo $row['event_type']; ?>
<?php echo $row['location']; ?>
</p>
<h1><?php echo $row['event_title']; ?></h1>
<p class="details"> <?php echo $row['date']; ?> | <?php echo $row['posted_by']; ?></p>
<p class="text">
<?php echo $row['event_details_short']; ?>
</p>
</div>
</article>
</div>
<?php endif; ?>
<?php $columnSelector++; // advance to the next row?>
<?php $columnSelector %= 3; // reset to zero every third event?>
<?php endwhile; ?>
It is probably the if statement don't let the code below to shown.
This line : <?php if ($columnSelector == 0): ?>
OK, solved it, the problem was the last tag here:
</article>
</div>
It was needed for when only one or two columns show but not for the third and so i replaced it with this.
</div>
</article>
<?php if ($columnSelector == 1){ ?>
</div>
<?php } ?>
<?php endif; ?>
And so now when there is three columns the div doesn't show and the layout is correct.

Reversing the second div set order with separate class in foreach loop

Reversing the second div set order with separate class in foreach loop.
It will be a shelf like structure. I tried to alternate the .tl .tr class.
OR
Can we able to use css to align the second set.
Code:
<?php foreach ($products as $product) { ?>
<div class="row">
<div class="shelf">
<div class="span4"><span class="tl">
<?php if ($product['thumb']) { ?>
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" />
<?php } ?>
</span></div>
<div class="span2">
<div class="name"><?php echo $product['name']; ?></div>
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
</div>
<?php } ?>
<div class="cart">
<input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" />
</div>
</div>
<div class="span2">Span 2</div>
<div class="span4"><span class="tr">Span4</span></div>
</div>
</div>
<?php } ?>
Css:
.shelf .tl {
margin-left: 58px;
}
.shelf .tr {
margin-left: -33px;
}
I think this will solve problem, it implements a counter to track whether current product should go on left or right
$product_counter = 0;
<?php foreach ($products as $product) { ?>
<?php $product_counter++; ?>
<?php if(!($product_counter%2 ==0)) { ?>
<div class="row">
<div class="shelf">
<div class="span4">
// image echo code here
</div>
<div class="span2">
// price, add to cart etc
</div>
<?php } else { ?>
<div class="span2">
// price, add to cart etc
</div>
<div class="span4">
// image echo code here
</div>
</div> <!-- shelf div closing tag -->
</div> <!-- row div closing tag -->
<?php } ?> <!-- closing else -->
<?php } ?> <!-- closing foreach-->
<!-- in case if there were odd numbers of total product, then close the row and shelf div after foreach -->
<?php if(!($product_counter%2 ==0)) { ?>
</div>
</div>
<? } ?>

Categories