I am creating a page with 4 different sections. In each section there is a responsive image and on the image there is text and some buttons. Right now they are aligned a bit off center and to the right. I am trying to achieve so that the 1st div the text and buttons float right and the 2nd div the text and buttons float left and so on. I am using the even odd nth property but it is only responding on the even css nth property. Here is the CSS and html. Keep in mind I am just using the background color now as an example and will put in the floats and padding if I get it working.
.popup-open:nth-child(odd) {
background: #ff0000;
}
.popup-open:nth-child(even) {
background: #000000;
}
<div class="popup-open">
<div class="icons-large">
<?php
$fields = CFS()->get('icons_large');
if($fields) :
foreach ($fields as $field) : ?>
<div class="row">
<div class="image">
<img src="<?php echo $field['icons_big'];?>" alt="">
</div>
</div>
<?php endforeach; endif; ?>
</div>
<div class="icons-large">
<?php
$fields = CFS()->get('tour_titles');
if($fields) :
foreach ($fields as $field) : ?>
<?php echo $field['tour_name'];?>
<?php endforeach; endif; ?>
</div>
<div class="title"><?php the_title(); ?></div>
</div>
I think you should add a class to the divs and target them that way, you will have more control over it too.
if($fields) :
$i = 1;
foreach ($fields as $field) :
if($i === 2){
$class = "even";
$i = 1;
}else if($i === 1){
$class = "odd";
$i = 2;
}
<div class="row <?=$class;?>">
<div class="image">
<img src="<?php echo $field['icons_big'];?>" alt="">
</div>
</div>
<?php endforeach; endif; ?>
Related
Sorry, I'm just a complete novice in PHP
Background: This code is a loop of three slider as you can see here - http://rashelectrical.com.au/. I need to make the H1 tag only on the first slide and make the other two H2 tag
Question:
How can I make the 2nd and last loop to H2 and H1 only on the first
loop?
Thanks
Here is my code:
https://jsfiddle.net/4jm5vhbf/
<?php while(have_rows('banner_slider')) : the_row();?>
<div class="sl" >
<div class="header-content relative-block align-center text-center flex-container align-middle" style="background:url('<?php the_sub_field('image');?>') no-repeat">
<div class="row">
<div class="columns">
<div class="header-content-inner relative-block animate-children">
<h3><?php the_sub_field('subheading');?></h3>
<h1><?php the_sub_field('heading');?></h1>
<p><?php the_sub_field('description');?></p>
<div class="button-group align-center">
<?php $n = 1; while(have_rows('button_links')) : the_row();
$link_lr = get_sub_field('link');?>
<?php if($n == 2){
$n2 = 'hollow';
}else{
$n2 = '';
}?>
<a class="button <?php echo $n2; ?>" href="<?php echo $link_lr['url']; ?>"><span><?php echo $link_lr['title']; ?></span></a>
<?php $n++; endwhile;?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile;?>
Its kinda hard to tell without seeing the full code, maybe something like that?
<!-- Instead of H3 tag here, use P tag with css class and change the font size with css -->
<h3><?php the_sub_field('subheading'); ?></h3>
<!-- count the heading elements -->
<?php $headings = count( get_sub_field( 'heading' ) ); ?>
<!-- Condition here if heading 1 echo H1 else echo H2 -->
<?php echo ($headings == 0) ? '<h1>' . the_sub_field('heading') . '</h1>' : '<h2>' . the_sub_field('heading') . '</h2>' ?>
<p><?php the_sub_field('description'); ?></p>
<!-- Your rest of code -->
Also for SEO and accessibility reasons, your HTML markup should considering the "Semantic" of your Heading tags .. so don't use H3 tag before H1 tag.
I've made a logo slider using Bootstrap (basically as seen here http://jsfiddle.net/juddlyon/Q2TYv/10/).
Within each slide there are 4 logos. I want to make this responsive, where on smaller screens it only shows 2 logos per slide. I'm not sure what the best way is to do this.
I can double the grid-4 width to 50% with media queries but then it will still show 4 per slide, in a 2x2 grid.
Another way is to duplicate the entire slide and hide and show the correct one, but this seems like a rather inefficient appreach.
So really I need to reduce the number of logos per slide as it is loaded.. but how?
I'm using WP and Advanced Custom Fields to populate the slider. Simplified code below:
PHP:
<?php
$firstslide = 0;
$slide = 0;
$repeater = get_field('clients', $clients);
$order = array();
foreach( $repeater as $i => $row ) {
$order[ $i ] = $row['name'];
}
array_multisort($order, SORT_ASC, $repeater);
if($repeater):
foreach($repeater as $i => $row):
if ($firstslide == 0) {
$class = "item active";
} else {
$class = "item";
};
if ($slide == 0) {
echo '<div class="' . $class . '">';
};
?>
<div class="grid-4">
<img src="<?php echo $row['logo']; ?>">
</div>
<?php
if ($slide == 4) {
echo '</div>';
$slide = 0;
} else {
$slide++;
}
$firstslide++;
endforeach;
wp_reset_postdata();
endif;
?>
This would results in something like:
<div class="item active">
<div class="grid-4"><img src="logo1.jpg"></div>
<div class="grid-4"><img src="logo2.jpg"></div>
<div class="grid-4"><img src="logo3.jpg"></div>
<div class="grid-4"><img src="logo4.jpg"></div>
</div>
<div class="item">
<div class="grid-4"><img src="logo5.jpg"></div>
<div class="grid-4"><img src="logo6.jpg"></div>
<div class="grid-4"><img src="logo7.jpg"></div>
<div class="grid-4"><img src="logo8.jpg"></div>
</div>
<div class="item">
<div class="grid-4"><img src="logo9.jpg"></div>
<div class="grid-4"><img src="logo10.jpg"></div>
<div class="grid-4"><img src="logo11.jpg"></div>
<div class="grid-4"><img src="logo12.jpg"></div>
</div>
Very simplified CSS for the grid:
.grid-4 {
width: 25%;
}
After more searching, it looks like Slick is a solution that will just take care this.
jsfiddle.net/BishopBarber/ufnjkjy4/1/
i have some items i want displayed in the view, my per page is set to 15, so each page displays 15 items, but i want to display ads in the middle of the loop, after maybe 4 items displayed, I've tried to put an if statement in the foreach loop to control the display, it displays the first 3 values, but when i put the div for the ad, it loops too, can someone please tell me what to do, or point me in the right direction?? thanks, here is my code so far:
<?php
$counter1 = 0;
//the foreach loop that retrieves the values from the controller
foreach($records as $record){
//an if statement to display the first 4 items..
if ($counter1 <= 3){
?>
<div class='box-scene'>
<div class='dbox'>
<div class='front face'>
<img src="images/newtag.png">
</div>
<a style="font-size:15px;" href="<?php echo base_url();?>music/<?php echo $record->url; ?>">
<div class="side face">
<span>
<?php echo $record->name; ?>
</span>
</div>
</a>
</div>
</div>
<?php
$counter1++;
}
?>
<div style="width:200px; height:200px; float:left; display:inline-block; margin: 0 12.5px 20px 12.5px;">
<div id="ad_200_200">
</div>
</div>
<!-- this div displays more than once, i dont know where to place it
for it to display after the first 3 items -->
<?php
}
?>
i want to know where to place the div, and how to continue displaying the items...thanks
Hi please use else condition.please check replace with below code
<?php
$counter1 = 0;
//the foreach loop that retrieves the values from the controller
foreach ($records as $record) {
//an if statement to display the first 4 items..
?>
<?php if($counter1 % 4 == 0) { ?>
<div style="width:200px; height:200px; float:left; display:inline-block; margin: 0 12.5px 20px 12.5px;">
<div id="ad_200_200">
</div>
</div>
<?php } ?>
<div class='box-scene'>
<div class='dbox'>
<div class='front face'>
<img src="images/newtag.png">
</div>
<a style="font-size:15px;" href="<?php echo base_url(); ?>music/<?php echo $record->url; ?>">
<div class="side face">
<span>
<?php echo $record->name; ?>
</span>
</div>
</a>
</div>
</div>
<!-- this div displays more than once, i dont know where to place it
for it to display after the first 3 items -->
<?php
$counter1++;
}
?>
use also an else statement like below:
<?php
$counter1 = 0;
foreach($records as $record){
if ($counter1 <= 3){ ?>
<div class='box-scene'>
<div class='dbox'>
<div class='front face'>
<img src="images/newtag.png">
</div>
<a style="font-size:15px;" href="<?php echo base_url();?>music/<?php echo $record->url; ?>">
<div class="side face">
<span>
<?php echo $record->name; ?>
</span>
</div>
</a>
</div>
<div>
<?php
$counter1++;
} else{ ?>
<div style="width:200px;height:200px;float:left;display:inline-block; margin: 0 12.5px 20px 12.5px;">
<div id="ad_200_200"></div>
</div>
<?php
$counter1 = 0;
} ?>
<?php
}
?>
I am using Advanced custom fields extension in my wordpress project. to show some custom content on a specific page, I have about 20 custom field in one page and i called them in theme file by like this way..
<?php if(get_field('name1') != ""): ?>
<div class="row-hardware">
<div class="partner-left"><img src="<? the_field('image1'); ?>" /></div>
<div class="partner-right">
<?php the_field('description1'); ?>
</div>
</div>
<?php endif; ?>
<?php if(get_field('name2') != ""): ?>
<div class="row-hardware">
<div class="partner-left"><img src="<? the_field('images2'); ?>" /></div>
<div class="partner-right">
<?php the_field('description2'); ?>
</div>
</div>
<?php endif; ?>
I called them for every single field, I saw in Advanced Custom fields it has drag and drop sorting area in admin area, but How can i call them as like sorting on theme file frontend.
is there any good solution ?
here i have attached images
thanks
Something like this should work (Not tested)
Note the <div class="clear"></div>. Add this to CSS:
.clear {
clear: both;
}
PHP:
<?php
$fields = get_field_objects();
$i = 0;
if ($fields) {
foreach ($fields as $field_name => $field) {
if (substr($field_name, 0, 5) == 'image' || substr($field_name, 0, 11) == 'description') {
if (($i % 2) == 0) {
echo '<div class="row-hardware">';
echo '<div class="partner-left"><img src="'.$field['value'].'" /></div>';
}
else {
echo '<div class="partner-right">'.$field['value'].'</div>';
echo '<div class="clear"></div></div>';
}
$i++;
}
}
}
?>
Last but not least. It's not that dynamic, but if your number of fields change constantly you should consider to create a custom post type.
<?php for ($i = 1; $i <= 19; $i++) : ?>
<div class="row-hardware">
<div class="partner-left"><img src="<?php the_field('image'.$i); ?>" /></div>
<div class="partner-right"><?php the_field('description'.$i); ?></div>
<div class="clear"></div></div>
<?php endfor; ?>
I have a parent page that acts as menu for my portfolio.
It pulls in thumbnail images from the child pages which i have been able to accomplish with magic fields and some code. It dumps the images into a grid layout. The thumbnails are pulled into one container div like so:
div id="folio-content">
<div class="thumb-container">
<div class="thumb"><img src="/images/pic.jpg"/>
</div>JCPenny</div>
... </div>`
when the div gets filled up with 2 thumbnails I want to create a new container div and fill it with 2 images again and so on after 2 images.
So, if you had 4 images it would look like this.
<div id="folio-content"><!--/Main Container/-->
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>JCPenny</div>
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>Champ Car</div></div>
<div id="folio-content"><!--/Main Container/-->
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>JCPenny</div>
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>Champ Car</div></div>
this is the code I am using in my page.php file.
<?php get_header(); ?>
<div id="folio-content">
<?php
$projectpage = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
$count = 0;
foreach($projectpage as $page)
{
$content = $page->post_content;
if(!$content)
continue;
if ($count == 10) --- this is geting 10 images now, but I want to get them all.
break;
$count++;
$content = apply_filters('the_content', $content);
?>
<div class="thumb-container">
<div class="thumb"><a href="<?php echo get_permalink($page->ID); ?>"<?php echo get_image ("thumbnail",1,1,1,$page->ID);?></a>
</div><?php echo $page->post_title ?>
</div>
<?php
}
?>
</div><!--/close set!-->
</div>
also, how can I get ALL child pages? I have it set to 10 now with this if ($count == 10)
any help? thanks a ton again!!!!
I'm not familiar with "get_pages" but since Wordpress treats posts and pages in an identical manner you could use this.
$projectpage = get_posts('numberposts=-1&post_type=page&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
The -1 removes the limit and gets ALL the specified pages.
I have cobbled together some code, that sort of sounds right but does not work at all! Which I am not surprised. But it is a starting point - please take a look at this code, maybe it is step in the right direction?
<?php
$projectpage = get_posts('numberposts=-1&post_type=page&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
if (have_posts()) :
$i=0; // counter
while(get_posts()) : the_post();
if($i%2==0) { // if counter is multiple of 3, put an opening div ?>
<!-- <?php echo ($i+1).'-'; echo ($i+2); ?> -->
<div>
<?php } ?>
<div class="single_item">
<h2><?php the_title(); ?></h2>
</div>
<?php $i++;
if($i%2==0) { // if counter is multiple of 3, put an closing div ?>
</div>
<?php } ?>
<?php endwhile; ?>
<?php
if($i%2!=0) { // put closing div here if loop is not exactly a multiple of 3 ?>
</div>
<?php } ?>
<?php endif; ?>