CSS Code Structure with PHP Loops Round 2 - php

Round 2: Trying to figure out why my content looks fine when screen size is under 992px but not when it is over. Everything looks fine in the lower screens but hardly anything is in the right place in full screen size. I have a feeling it's because of the containers inside the loop, but I'm not sure how to properly take them out without it forcing everything into a narrow column from the .col-md-1 container.
<?php get_header(); ?>
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Blog</h1>
<ol class="breadcrumb">
<li>Home
</li>
<li class="active">Blog</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="col-md-1 text-center">
<p><?php the_time('l, F jS, Y'); ?></p>
</div>
<?php if ( has_post_thumbnail() ) : ?>
<div class="col-md-5">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'large', array( 'class' => 'img-responsive img-hover' ) ); ?>
</a>
</div>
<?php endif; ?>
<div class="col-md-6">
<h3>
<?php the_title(); ?>
</h3>
<p>by <?php the_author_posts_link(); ?>
</p>
<p><?php the_excerpt(); ?></p>
<a class="btn btn-primary" href="<?php the_permalink(); ?>">Read More <i class="fa fa-angle-right"></i></a>
</div>
<hr>
<?php endwhile; ?>
<div class="navigation"><p><?php posts_nav_link('','« Newer Posts','Older Posts »'); ?></p></div>
</div>
<?php include 'include.php'; ?>
</div>
<?php else: ?>
<p><?php _e('Sorry, there are no posts.'); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
Any insight is greatly appreciated :)

As has been mentioned by others, you need to use some additional grid classes.
For your 8 | 4 grid to work on medium and large devices, you would need to use col-md-8 col-lg-8 on your content area and col-md-4 col-lg-4 on your sidebar.
You'll also want to make sure that your blog posts grids have col-lg-* classes alongside their col-md-* classes.
For your layout to work properly on mobile and tablet devices you'll also want to add some col-xs-* and col-sm-* classes.
For more information on the Bootstrap grid system, I would recommend you view: https://getbootstrap.com/css/#grid

My guess is that its because you are using
<div class="col-lg-8">
but not filling the remaining 4 columns at the lg size (and all contained elements are of the-md class so display fine) and also not clearing the float - so at lg size your elements will be floating next to each other and out of position at the large size but not at smaller sizes where they will display as full rows.
you need to rethink your layout (and either have it go full screen) or add a clearfix class to the parent rows to ensure that the floats are cleared before adding the next row.
Always remember that 12 is the magic number - you don't have to use all the columns (and having col-lg-8 is absolutely fine) but if you dont fill the row you need to clear the float from it - Bootstrapp adds a float:left to the column classes - hence giving your dodgy layout only at the lg size.

Just give it a try with
col-xs-
col-md-
col-lg-
col-xl-
if you need any other info just see the bootstrap "grid system"
http://getbootstrap.com/css/#grid-options

Related

Toggle Show/Hide Configuration on Mobile - ACF Repeater

I am using the ACF Repeater to create rows of images/content and to show/hide when clicked. Everything looks good on desktop screens, with a row of 3 images, when an image is clicked, the hidden div shows up below and the background color toggles on so you know which image's content you are looking at.
My problem, is I am trying to get the same functionality on mobile, but when an image is clicked, the content shows up under the 3rd div. I want to be below the image that was clicked. Since I am using the ACF repeater, my php script creates the parent div (3 across) first and then the hidden divs below.
I don't mind creating a separate html markup for mobile, I just can't figure out how to make it work with the ACF repeater.
<div class="staff">
<?php if (have_rows('staff_rows')):
while (have_rows('staff_rows')): the_row(); ?>
<div class="staff-wrap">
<div class="staff_images">
<?php if (have_rows('staff_images')):
while (have_rows('staff_images')): the_row(); ?>
<a href="#/" class="<?php the_sub_field('staff_class'); ?> show staff-box">
<img src="<?php the_sub_field('staff_image'); ?>"><div class="image-box"><h3>
<?php the_sub_field('staff_name'); ?></h3>
<h3><?php the_sub_field('staff_position'); ?></h3></div>
</a>
<?php endwhile;
endif; ?>
<?php if (have_rows('staff_bios')):
while (have_rows('staff_bios')): the_row(); ?>
<div class="bios">
<div class="wrap">
<div class="<?php the_sub_field('bio_class'); ?> row"><?php
the_sub_field('bio_text'); ?></div>
</div>
</div>
<?php endwhile;
endif; ?>
</div>
http://toolboxdevmachine.com/TechNiche/about-us
Thanks for your help
I'm guessing you've already figured this out by now, in 2019. It looks like you are missing a few closing <div> tags, as well as ending your while loop and the primary conditional. I broke out the code, indented it and wrote it with the correct closing tags:
<div class="staff">
<?php if (have_rows('staff_rows')):
while (have_rows('staff_rows')): the_row(); ?>
<div class="staff-wrap">
<div class="staff_images">
<?php if (have_rows('staff_images')):
while (have_rows('staff_images')): the_row(); ?>
<a href="#/" class="<?php the_sub_field('staff_class'); ?> show staff-box">
<img src="<?php the_sub_field('staff_image'); ?>">
<div class="image-box">
<h3><?php the_sub_field('staff_name'); ?></h3>
<h3><?php the_sub_field('staff_position'); ?></h3>
</div>
</a>
<?php endwhile;
endif; ?>
<?php if (have_rows('staff_bios')):
while (have_rows('staff_bios')): the_row(); ?>
<div class="bios">
<div class="wrap">
<div class="<?php the_sub_field('bio_class'); ?> row">
<?php the_sub_field('bio_text'); ?>
</div>
</div>
</div>
<?php endwhile;
endif; ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>

Issues rendering pagination with WP_Query

I'm having a major issue with trying to render Wordpress pagination. I'm not that good with PHP and I've tried just about every solution I can Google. Some of the queries "work" in that they display a set of page numbers, but they break when I add more variables.
For example, when I told it to display ALL pages, it did just that, but then I couldn't limit it using mid_size or any of that. So it was kind of "display all" (which I don't want), or nothing at all. I'm not sure what's breaking, so any pushes in the right direction would be excellent.
My objective: Create a list of numbered page links that truncate properly so it looks like:
[ 1 2 3 ... 97 98 99 ]
Thanks to anyone who can help me out. I'm running Wordpress 4.9.7.
My code looks like this:
<!-- post loop -->
<div class="auto cell">
<?php
// the query
$wpb_all_query = new WP_Query(array('post_type'=>'review', 'posts_per_page' => 3, 'orderby'=>'name', 'order'=>'ASC')); ?>
<?php if ( $wpb_all_query->have_posts() ) : ?>
<!-- start of main news loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
<div class="grid-x grid-margin-x">
<div class="cell large-2 small-2">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="thumbnail">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/img/default_thumb.png" alt="<?php the_title(); ?>" />
<?php } ?></a>
</div>
<div class="cell large-10 small-10">
<h2><?php the_title(); ?></h2>
<span class="post-meta"> By <?php the_author_posts_link(); ?> · <?php the_time('F jS, Y, g:i A'); ?> <?php edit_post_link(__('Edit This'), ''); ?></span>
<ul class="list-meta">
<li>Developer: <?php echo(types_render_field( 'game-developer' )); ?></li>
<li>Genre: <?php echo(types_render_field( 'game-genre' )); ?></li>
</ul>
</div>
<div class="post-categories cell"><?php the_category(', '); ?></div>
</div>
<?php endwhile; ?>
<!-- start of pagination -->
<div class="row">
<?php if (function_exists("pagination")) {
pagination($custom_query->max_num_pages);
} ?>
</div>
<!-- end of pagination -->
<!-- end of main news loop -->
I use this plugin for my pagination. It gives you a settings screen in the back end where you can set up how it's numbered. Hope it helps!

ACF Repeater Field Rows and Columns

So I need to use the repeater field in ACF to output a section of my website. The way I have it set up it creates a new <div class="row landing-item"> every time its called. I need it to create that every 2 times so the html will be correct for the layout.
<section class="row landing">
<h2>Featured Sections</h2>
<?php if( have_rows('landing_page_landing_items') ): ?>
<?php while ( have_rows('landing_page_landing_items') ) : the_row(); ?>
<div class="row landing-item">
<div class="small-12 medium-6 columns">
<img src="<?php the_sub_field('landing_image'); ?>">
<h3><?php the_sub_field('landing_title'); ?></h3>
<p><?php the_sub_field('landing_text'); ?></p>
<a class="button" href="<?php the_sub_field('landing_link'); ?>">Learn More</a>
</div>
</div><!-- end landing-item -->
<?php endwhile; ?>
<?php endif; ?>
If you look at the above the end result I need is a row with 2 columns, then row with 2 columns and so on and so on. Again right now it gives me a row with 1 column every time. I tried moving about the script initiations outside and inside the rows and columns but could not get the right sequence.
It looks like you may be able to accomplish your end goal by using the Foundation Block Grid feature rather than the standard grid. If you use the block grid, You'll continue to repeat row after row based only on the number of items in the list. See below:
<section class="row landing">
<h2>Featured Sections</h2>
<div class="row landing-item">
<ul class="small-block-grid-1 medium-block-grid-2">
<?php if( have_rows('landing_page_landing_items') ): ?>
<?php while ( have_rows('landing_page_landing_items') ) : the_row(); ?>
<li>
<img src="<?php the_sub_field('landing_image'); ?>">
<h3><?php the_sub_field('landing_title'); ?></h3>
<p><?php the_sub_field('landing_text'); ?></p>
<a class="button" href="<?php the_sub_field('landing_link'); ?>">Learn More</a>
</li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div><!-- end all landing items -->
</section>
You may need to do some CSS if you'd need to do any special per row editing. I'm thinking this may be one solution to your dilemma though.

Issue with ACF fields showing up in WordPress template

Okay, I am having the most bizarre issue ever. I have a custom home page template for a WordPress site I am working on.
You can see a screenshot of how I have my ACF fields for this template setup on the backend here.
The issue I am having is that when I try to display the field
<img src="<?php the_field('slide_1_thumb'); ?>" alt="" />
the image doesn't show up at all. I have the Return Value set to 'Image URL', and the odd thing is that it shows the images for
<?php the_field('slide_1'); ?>
just fine with no issues at all.
I'm not sure what I am doing wrong here, but there are no spelling errors at all, for some reason those slide_1_thumb images won't show up. I want to think this is one of those Occam's Razor type of situations where I missed something so simple, but I've gone over this a million times with no luck.
Below you will find a copy of the PHP code for my home-page.php template.
<?php
/**
* Template Name: Home Page
*
* A custom template for the home page.
*
* The "Template Name:" bit above allows this to be selectable
* from a dropdown menu on the edit page screen.
*/
get_header(); ?>
<div id="slideshow-container">
<div id="slideshow" class="slideshow pcfcu-theme">
<div class="slideshow-img" style="background-image: url(<?php the_field('slide_1'); ?>);">
<div class="slideshow-img-inner">
<div class="slideshow-img-text">
<h1><?php the_field('slide_1_title'); ?></h1>
<p><?php the_field('slide_1_description'); ?></p>
</div>
</div>
</div>
<div class="slideshow-img" style="background-image: url(<?php the_field('slide_2'); ?>);">
<div class="slideshow-img-inner">
<div class="slideshow-img-text">
<h1><?php the_field('slide_2_title'); ?></h1>
<p><?php the_field('slide_2_description'); ?></p>
</div>
</div>
</div>
<div class="slideshow-img" style="background-image: url(<?php the_field('slide_3'); ?>);">
<div class="slideshow-img-inner">
<div class="slideshow-img-text">
<h1><?php the_field('slide_3_title'); ?></h1>
<p><?php the_field('slide_3_description'); ?></p>
</div>
</div>
</div>
</div>
</div>
<div id="content-container">
<div id="content-container-inner">
<div id="recent-blog-entries-container">
<div id="recent-blog-entries">
<header><h1>Recent Blog Entries</h1></header>
<?php $postslist = get_posts('numberposts=2&order=DESC&orderby=date');
foreach ($postslist as $post) : setup_postdata($post);
?>
<h2 class="rbe-title"><?php the_title(); ?></h2>
<p class="rbe-posted-on">Posted on: <?php the_time(get_option('date_format')) ?></p>
<div class="rbe-excerpt"><?php the_excerpt(); ?></div>
<?php endforeach; ?>
</div>
</div>
<div id="features">
<header><h1>Features</h1></header>
<a class="goTo1"><div class="feature-thumb"><img src="<?php the_field('slide_1_thumb'); ?>" alt="" /></div></a>
<a class="goTo2"><div class="feature-thumb"><img src="<?php the_field('slide_2_thumb'); ?>" alt="" /></div></a>
<a class="goTo3"><div class="feature-thumb"><img src="<?php the_field('slide_3_thumb'); ?>" alt="" /></div></a>
</div>
</div>
</div>
<?php get_footer(); ?>
Another strange thing is that if you take one of the working ACF images such as
<?php the_field('slide_1'); ?>
it works perfectly and outputs the image, but when you move it down to the 'Features' section of the code to see if it will work in place of one of those small feature thumbnails, it won't work in that portion of the code. It's almost as if that bottom 'Features' portion of the page has some sort of error, but I don't see any errors at all in my code.
In other words, ALL of this code works perfect up until the very last portion of it with the 'feature' thumbnail images. You can see this live on the website here.
When making a new loop using get_posts(), you should end it with the wp_reset_postdata() function to reset your loop's data back to what it was before the get_posts(). So try this:
<div id="recent-blog-entries">
<header><h1>Recent Blog Entries</h1></header>
<?php $postslist = get_posts('numberposts=2&order=DESC&orderby=date');
foreach ($postslist as $post) : setup_postdata($post); ?>
<h2 class="rbe-title"><?php the_title(); ?></h2>
<p class="rbe-posted-on">Posted on: <?php the_time(get_option('date_format')) ?></p>
<div class="rbe-excerpt"><?php the_excerpt(); ?></div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</div>
Adding the wp_reset_postdata() after your loop should fix this for you.
Okay, I have NO idea what was going on, but all I had to do to fix this was delete the ACF fields on the backend and then recreate them with the EXACT same names as before. Sure enough that fixed it.
So, while I don't have a conclusive answer as to why this was happening, all I can say is that it must have been some sort of odd glitch.

Custom wordpress results page invidual results are listed from the bottom up(opposite dynamic code). How can I change this?

I am using
<?php get_search_form(); ?>
in my header. And the code that is dynamically produced lists the items from top to bottom but they show up bottom to top and going into my banner.
I can only control where the bottom (first) result lands on the page so moving it down to create room would be useless if the search only brought back a few results.
I have tried to set the height and use overflow: scroll; but for some reason the page can't handle it and it only shows a couple results regardless of the container height.
I am no PHP guru but I can generally follow along and make corrections. I got this PHP for the results page from this site.
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2 class="title"><?php the_title(); ?></h2>
<p class="meta"><small>Posted on <?php the_time('F jS, Y') ?> by <?php the_author() ?> <?php edit_post_link('Edit', ' | ', ''); ?></small></p>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
The site is currently here http://testsite.saltrockdesign.com/
It is a custom site for a school project but a real client also. Obviously not finished..
Any help will result in much love and happiness from me.
Well I can't explain WHY it's happening. It's certainly peculiar. But I can tell you where the problem is and how to fix it.
For some reason, this is making everything appear backwards:
.title {
margin-top: -350px;
}
Get rid of that, and you can also get rid of the margin-top setting in .page4 and .span8. Then just pick one of those last two elements and put in a single margin-top which gets you to where you want to be.

Categories