PHP affecting column layout - php

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.

Related

Looking to make archive.php display in two columns for Wordpress site

Very new Wordpress apprentice here. Trying to get my archive page to display posts in two columns going like:
Post 1 Post 2
Post 3 Post 4
Here is an example from a figma we were working on: https://ibb.co/N3XwtwD
My question is, what code can I add to my files to allow this? I currently have some bootstrap classes on the html portion I inserted here and it is displaying as one column, so I don't know if those classes will interfere with anything. Here is my archive.php code below:
<?php
get_header();
?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
while(have_posts()) {
the_post(); ?>
<div class="row">
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<img class="img-fluid mb-3"<?php
the_post_thumbnail();
?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
</div>
<?php }
echo paginate_links();
?>
</div>
<?php
get_footer();
?>
First time posting here so apologies if I left anything important out. Really appreciate this place!
Thanks!
You need to create a row every two posts and you have to add <div class="col-lg-6"> two times in a row. check below code.
<?php get_header(); ?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
$count = 1;
while( have_posts() ) { the_post();
if ( $count % 2 == 1){ ?>
<div class="row">
<?php } ?>
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<?php the_post_thumbnail(); ?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
<?php if ( $count % 2 == 0 ){ ?>
</div>
<?php } $count++; ?>
<?php }
if ( $count % 2 != 1 ) echo "</div>";
echo paginate_links(); ?>
</div>
Please replace with the below code that helps you.
<?php
get_header();
?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
$counterval = 0;
while(have_posts()) {
the_post();
$counterval++;
if($counterval % 2 != 0)
{ ?>
<div class="row">
<?php } ?>
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
if(!empty($featured_img_url)){ ?>
<img class="img-fluid mb-3" src="<?php echo esc_url($featured_img_url); ?>" />
<?php } ?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
<?php
if($counterval % 2 == 0)
{ ?>
</div>
<?php } ?>
<?php } ?>
<?php echo paginate_links();
?>
</div>
<?php
get_footer();
?>

advanced custom fields can't do nested loops repeater inside repeater have_rows() not doing anything

I have a repeater inside a repeater and I need to loop what is in it.
I'm following this: https://www.advancedcustomfields.com/resources/have_rows/
This is my field structure:
agenda_section_events (parent/repeater)
agenda_event_time_pacific (text)
agenda_event_time_eastern (text)
agenda_event_title (text)
agenda_event_speakers (repeater)
agenda_event_speaker_headashot (image array)
agenda_event_speaker_name (text)
agenda_event_speaker_title (text)
agenda_event_speaker_content (wysiwyg editor)
So with that in mind, as I understand it, I need to loop over agenda_section_events and inside that I need to get rows https://www.advancedcustomfields.com/resources/have_rows/
So that code looks like this:
<div class="tc__agenda-items">
<?php foreach($agendaSectionEvents as $agendaSectionEvent): ?>
<div class="tc__agenda-item">
<div class="tc__agenda-time">
<div class="tc__agenda-time--pacific">
<?php echo $agendaSectionEvent['agenda_event_time_pacific'] ?>
</div>
<div class="tc__agenda-time--eastern">
<?php echo $agendaSectionEvent['agenda_event_time_eastern'] ?>
</div>
</div>
<h3><?php echo $agendaSectionEvent['agenda_event_title'] ?></h3>
<div class="tc__agenda-speaker-list">
<!-- DEBUG LINE - BUT ITS EMPTY -->
<div style="color: red;"><?php echo have_rows('agenda_event_speakers') ?></div>
<?php if(have_rows('agenda_event_speakers')): ?>
<div class="tc__agenda-speaker">
<?php while(have_rows('agenda_event_speakers')): ?>
<div class="tc__agenda-speaker-headshot">
<img src="<?php the_sub_field('agenda_event_speaker_headashot')['url'] ?>" alt="<?php the_sub_field('agenda_event_speaker_headashot')['alt'] ?>">
</div>
<div class="tc__agenda-speaker-info">
<h4><?php the_sub_field('agenda_event_speaker_name') ?></h4>
<p><?php the_sub_field('agenda_event_speaker_title') ?></p>
</div>
<?php endwhile ?>
</div>
<?php endif ?>
</div>
Learn More
</div>
<?php endforeach ?>
</div>
I'm really confused because all my field names are right, and the fields inside the second loop are sub fields but nothing is showing.
Why would that be?
I then thought its because I did a have rows inside a for each so then I tried doing a while inside a while like the acf docs
<div class="tc__agenda-items">
<?php while(have_rows('agenda_section_events')): ?>
<div class="tc__agenda-item">
<div class="tc__agenda-time">
<div class="tc__agenda-time--pacific">
<?php echo $agendaSectionEvent['agenda_event_time_pacific'] ?>
</div>
<div class="tc__agenda-time--eastern">
<?php echo $agendaSectionEvent['agenda_event_time_eastern'] ?>
</div>
</div>
<h3><?php echo $agendaSectionEvent['agenda_event_title'] ?></h3>
<div class="tc__agenda-speaker-list">
<!-- DEBUG LINE - BUT ITS EMPTY -->
<div style="color: red;"><?php echo have_rows('agenda_event_speakers') ?></div>
<?php if(have_rows('agenda_event_speakers')): ?>
<div class="tc__agenda-speaker">
<?php while(have_rows('agenda_event_speakers')): ?>
<div class="tc__agenda-speaker-headshot">
<img src="<?php the_sub_field('agenda_event_speaker_headashot')['url'] ?>" alt="<?php the_sub_field('agenda_event_speaker_headashot')['alt'] ?>">
</div>
<div class="tc__agenda-speaker-info">
<h4><?php the_sub_field('agenda_event_speaker_name') ?></h4>
<p><?php the_sub_field('agenda_event_speaker_title') ?></p>
</div>
<?php endwhile ?>
</div>
<?php endif ?>
</div>
Learn More
</div>
<?php endwhile ?>
</div>
<?php endif ?>
Since implementing this change, now the page just...doesn't load!? What!?
How do you do a nested for loop in advanced custom fields?
You need to add the_row(); inside your while loops. All ACF loops are formatted the same, nested or not. Something I do to keep it easy is make the if/while/the_row stuff all one line, see below:
Start loops like this:
<?php if (have_rows('agenda_section_events')): while (have_rows('agenda_section_events')) : the_row(); ?>
End loops like this:
<?php endwhile; endif; ?>
You can go wild with the number of loops you want to nest, just simply copy the parent loop lines and create a nested one, then change your row to the nested one of course.
I adjusted your code below, give this a shot.
You should also define your subfield array values inside the loop you're using it with, just keeps things cleaner – or just use the_sub_field to echo your subfield values since its a short function anyway.
<div class="tc__agenda-items">
<?php if (have_rows('agenda_section_events')): ?>
<?php while (have_rows('agenda_section_events')) : the_row(); ?>
<div class="tc__agenda-item">
<div class="tc__agenda-time">
<div class="tc__agenda-time--pacific">
<?php echo $agendaSectionEvent['agenda_event_time_pacific'] ?>
</div>
<div class="tc__agenda-time--eastern">
<?php echo $agendaSectionEvent['agenda_event_time_eastern'] ?>
</div>
</div>
<h3><?php echo $agendaSectionEvent['agenda_event_title'] ?></h3>
<div class="tc__agenda-speaker-list">
<!-- DEBUG LINE - BUT ITS EMPTY -->
<div style="color: red;"><?php // echo have_rows('agenda_event_speakers') ?></div>
<?php if (have_rows('agenda_event_speakers')) ?>
<div class="tc__agenda-speaker">
<?php while (have_rows('agenda_event_speakers')) : the_row(); ?>
<div class="tc__agenda-speaker-headshot">
<img src="<?php the_sub_field('agenda_event_speaker_headashot')['url'] ?>" alt="<?php the_sub_field('agenda_event_speaker_headashot')['alt'] ?>">
</div>
<div class="tc__agenda-speaker-info">
<h4><?php the_sub_field('agenda_event_speaker_name') ?></h4>
<p><?php the_sub_field('agenda_event_speaker_title') ?></p>
</div>
<?php endwhile ?>
</div>
<?php endif ?>
</div>
Learn More
</div>
<?php endwhile ?>
<?php endif ?>

Image height not working on php loop

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>

not able to call a codeigniter function using form_open

In codeigniter currently I am working on shopping cart but the problem is I am not able to call a function using form_open in codeigniter.
However, in the same project in another place same code is working properly but in other view form_open it's not working.
Here is my code:
<?php if(count($data)):?>
<?php foreach($data as $head_data) :?>
<div class="row">
<?php echo form_open('Shopingcart/add',['class'=>'form-horizontal']);?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="imagebox">
<img src=<?php echo base_url($head_data->p_image)?> class="" alt="picture">
<h2>New This Week</h2>
<p>Browse New Portraits and Abstracts</p>
<p id="id"><?= $head_data->p_id ?></p>
<p id="p_price"><?= $head_data->p_price ?></p>
<p id="p_name"><?= $head_data->p_name ?></p>
<?= anchor('Stuff','View Collections',['class'=>'btn btn-primary'])?>
<?php
echo form_hidden('id', $head_data->p_id);
echo form_hidden('qty', 1);
echo form_hidden('name', $head_data->p_name);
echo form_hidden('price', $head_data->p_price);
?>
<p><?php echo form_submit('', 'Add to Cart'); ?></p>
<?php echo form_close(); ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p> No content found</p>
<?php endif ?>
check to see if you are loading the helper.
$this->load->helper('form');
somewhere in your code. preferably in the constructor.
also make sure that error notifications are are turned on, these sorts of problems should give errors that help.
change your code with below one
<?php if(count($data)):?>
<?php foreach($data as $head_data) :?>
<div class="row">
<?php echo form_open('Shopingcart/add',array('class'=>'form-horizontal'));?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="imagebox">
<img src=<?php echo base_url($head_data->p_image)?> class="" alt="picture">
<h2>New This Week</h2>
<p>Browse New Portraits and Abstracts</p>
<p id="id"><?= $head_data->p_id ?></p>
<p id="p_price"><?= $head_data->p_price ?></p>
<p id="p_name"><?= $head_data->p_name ?></p>
<?= anchor('Stuff','View Collections',array('class'=>'btn btn-primary'))?>
<?php
echo form_hidden('id', $head_data->p_id);
echo form_hidden('qty', 1);
echo form_hidden('name', $head_data->p_name);
echo form_hidden('price', $head_data->p_price);
?>
<p><?php echo form_submit('', 'Add to Cart'); ?></p>
</div>
</div>
<?php echo form_close(); ?>
<?php endforeach; ?>
<?php else: ?>
<p> No content found</p>
<?php endif ?>

Make image as a link in Codeigniter

I am trying to make image as a link in Codeigniter but <a> tag is not working. I am trying to make image as a link but inside foreach loop <a> tag is not working.
Here is my code
<?php if(count($trendpost)):?>
<?php if(count($trendpost)<=3):?>
<div class="row">
<?php foreach($trendpost as $post): ?>
<div class="col-lg-4 col-md-4">
<a href=<?php echo site_url($post->url)?>> <img class="imageborder trendimg" src=<?php echo site_url($post->link)?>></a>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="row">
<?php foreach($trendpost as $post) :?>
<div class="col-lg-4 col-md-4">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php endif ?>
<?php else: ?>
<p> not found</p>
<?php endif ?>
</div>
</div>
change your code to this and please check again.
<?php if(count($trendpost)):?>
<?php if(count($trendpost)<=3):?>
<div class="row">
<?php foreach($trendpost as $post): ?>
<div class="col-lg-4 col-md-4">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="row">
<?php foreach($trendpost as $post) :?>
<div class="col-lg-4 col-md-4">
<a href="<?php echo site_url($post->url)?>" style="display: block;">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>></a>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php endif ?>
<?php else: ?>
<p> not found</p>
<?php endif ?>
You can use
<?php echo anchor('your Controller_name/link','<img src="your path" /> ','class="btn btn-default btn-flat"')?>
instead of anchor Tag

Categories