Insert ACF filed into CSS pseudo element - php

I have this section on my website:
This is on my homepage, pulling through items of a custom post type called products.
Each product has it's own product colour, I've allowed the user to select this from an Advanced Custom Field Colour Picker.
I've created the Arrows using CSS :before and :after (one for the line and one for the arrow head), so I could colour them using the product colour ACF.
This would mean I would have to apply the colour inline, inside the template. But as I have used Pseudo classes, I don't believe I can style them inline.
To get around this I added a style block inside my loop... This seems to work but it's only taking the yellow colour as I assume it's the first colour it finds...
Is there a way around this? I'm not sure if I'm making it too complex...
Here's the separate CSS from the CSS document:
.products-item-inner .arrow-right:after {
content: "";
border: solid;
/* border-color: <?php the_field('product_colour'); ?>; */
border-width: 0 2px 2px 0;
display: inline-block;
vertical-align: middle;
padding: 5px;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
margin-left:-12px;
}
.products-item-inner .arrow-right:before {
width: 30px;
height: 2px;
/* background-color: <?php the_field('product_colour'); ?>;*/
content: "";
display: inline-block;
vertical-align: middle;
}
Here's the template loop with the added CSS <style> inline:
<div class="container">
<div class="row">
<?php
$args = array(
'post_type' => 'products',
'posts_per_page' => 9999,
'orderby' => 'none'
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- <a href="<?php the_permalink(); ?>"> -->
<div class="col-lg-4 products-item-outer">
<div class="col-12 products-item-inner">
<style type="text/css">
.products-item-inner .arrow-right:after { border-color: <?php the_field('product_colour'); ?>; }
.products-item-inner .arrow-right:before { background-color: <?php the_field('product_colour'); ?>; }
</style>
<div class="logo">
<?php
$image = get_field('logo');
if( !empty( $image ) ): ?>
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
<?php endif; ?>
</div>
<div class="excerpt"><p><?php the_field('excerpt_text'); ?></p></div>
<div class="read-more-link">Read More<span class="arrow-right"></span></div>
</div>
</div>
<!-- </a> -->
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
</div>
Thanks for looking :)

Older browser support method
For maximum browser support, you can use the style attribute to assign a colour to your .arrow-right element, and can leverage currentColor in its pseudo-elements:
<div class="container">
<div class="row">
<?php
$args = array(
'post_type' => 'products',
'posts_per_page' => 9999,
'orderby' => 'none'
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- <a href="<?php the_permalink(); ?>"> -->
<div class="col-lg-4 products-item-outer">
<div class="col-12 products-item-inner">
<div class="logo">
<?php
$image = get_field('logo');
if( !empty( $image ) ): ?>
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
<?php endif; ?>
</div>
<div class="excerpt"><p><?php the_field('excerpt_text'); ?></p></div>
<div class="read-more-link">Read More<span class="arrow-right" style="color: <?php the_field('product_colour'); ?>;"></span></div>
</div>
</div>
<!-- </a> -->
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
</div>
.products-item-inner .arrow-right:after {
content: "";
border: solid;
border-color: currentColor;
border-width: 0 2px 2px 0;
display: inline-block;
vertical-align: middle;
padding: 5px;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
margin-left:-12px;
}
.products-item-inner .arrow-right:before {
width: 30px;
height: 2px;
background-color: currentColor;
content: "";
display: inline-block;
vertical-align: middle;
}
CSS Custom Property method
You could also use a CSS custom property, if you need the colour in more than one spot, where the method above won't work (unless you repeat the colour definition in several places).
I added it to your .products-item-outer element as a style attribute. This will cascade down into your .arrow-right pseudo-elements. I also added a fallback colour of rebeccapurple in this example, in case the value is missing.
<div class="container">
<div class="row">
<?php
$args = array(
'post_type' => 'products',
'posts_per_page' => 9999,
'orderby' => 'none'
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- <a href="<?php the_permalink(); ?>"> -->
<div class="col-lg-4 products-item-outer" style="--product-color: <?php the_field('product_colour'); ?>;">
<div class="col-12 products-item-inner">
<div class="logo">
<?php
$image = get_field('logo');
if( !empty( $image ) ): ?>
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
<?php endif; ?>
</div>
<div class="excerpt"><p><?php the_field('excerpt_text'); ?></p></div>
<div class="read-more-link">Read More<span class="arrow-right"></span></div>
</div>
</div>
<!-- </a> -->
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
</div>
.products-item-inner .arrow-right:after {
content: "";
border: solid;
border-color: var(--product-color, rebeccapurple);
border-width: 0 2px 2px 0;
display: inline-block;
vertical-align: middle;
padding: 5px;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
margin-left:-12px;
}
.products-item-inner .arrow-right:before {
width: 30px;
height: 2px;
background-color: var(--product-color, rebeccapurple);
content: "";
display: inline-block;
vertical-align: middle;
}

Related

How to add mouseover text to Wordpress featured image thumbnails?

I am using the Wordpress theme "Photos"
It generates thumbnails for posts on the home page using featured images. Thumbnails fade on hover, but no post title is displayed. http://www.hardeepasrani.com/demo/photos/
.photogrid-item img.featured-image:hover {
opacity: 0.2;
}
I have found numerous wordpress plugins and numerous examples online of how to accomplish thumbnail hover captions, but the wordpress plugins affect the feature images accompanying posts rather than the thumbnails on the home page, and the online examples are simple html/css whereas I believe this theme needs me to put it in the content.php file.
<div id="post-<?php the_ID(); ?>" <?php post_class('photogrid-item'); ?>>
<a class="photogrid-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<img class="featured-image" src="<?php echo $feat_image; ?>" />
<?php else: ?>
<?php $feat_image = get_stylesheet_directory_uri() . '/assets/images/default.jpg'; ?>
<img class="featured-image" src="<?php echo $feat_image; ?>" />
<?php endif; ?>
</a>
</div>
w3schools has a nice, simple example, but it overlays predefined text ("Hello World") https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_fade
<div class="container">
<img src="img_avatar.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
How can I integrate this so that it will display the corresponding post title to every thumbnail?
--------------UPDATE---------------
Using developerme's answer, I got most of the way there. But hovering over any of the thumbnails made the overlays show up for all of the thumbnails. For some reason this was fixed by editing the CSS from
.container:hover .overlay {
opacity: 1;
}
to:
.overlay:hover {
opacity: 1;
}
I have no idea why, but that seems to do the trick.
<style>
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.overlay:hover {
opacity: 1;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
</style>
<div id="post-<?php the_ID(); ?>" <?php post_class('photogrid-item'); ?>>
<a class="photogrid-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<img class="featured-image" src="<?php echo $feat_image; ?>" />
<div class="overlay">
<div class="text"><?php the_title(); ?></div>
</div>
<?php else: ?>
<?php $feat_image = get_stylesheet_directory_uri() . '/assets/images/default.jpg'; ?>
<img class="featured-image" src="<?php echo $feat_image; ?>" />
<?php endif; ?>
</a>
</div>
Could You Please try Following code with the css.You change the css with your own needs.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.overlay:hover {
opacity: 1;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<img alt="Avatar" class="image"> src="<?php echo $feat_image; ?>" />
<?php else: ?>
<?php $feat_image = get_stylesheet_directory_uri() . '/assets/images/default.jpg'; ?>
<img alt="Avatar" class="image">src="<?php echo $feat_image; ?>" />
<?php endif; ?>
<div class="overlay">
<div class="text"><?php the_title(); ?></div>
</div>
</a>
</div>
</body>
</html>
The majority of browsers will display the image title on hover. Assuming that your theme adds the title to the code (the HTML will look something like <img src='image.jpg' title='my great image' />) then all you need to so is go through the images in your media library and make sure that the title field is filled in.
Hope that helps

How do I horizontally align images in WordPress once turned into a PHP loop?

I want to unpack the question so that it is clear and you will see the code below. I turned my HTML Bootstrap page into a WordPress dynamic site. The images are no longer under the img tag. So if you look below, I am not sure if I need to be tweaking the col-xl-2 class or creating a has_post_thumbnail selector in CSS. I need for my images to go from vertically aligned to horizontally aligned. If you look at the The col-centered keeps it centered, but I need it to be horizontally aligned. I have tried following the guidance in the WordPress Codex regarding styling the_post_thumbnail and it has not helped.
This is my index.php file:
<?php
// Advanced Custom Fields
// this is a bunch of variables with our fields to echo out in PHP
$images_feature_title = get_field('images_feature_title');
$images_feature_body = get_field('images_feature_body');
$indianapolis_feature_title = get_field('indianapolis_feature_title');
$indianapolis_feature_body = get_field('indianapolis_feature_body');
$social_media_image = get_field('social_media_image');
$social_media_title = get_field('social_media_title');
$social_media_feature_body = get_field('social_media_feature_body');
?>
<?php get_header(); ?>
<!-- Carousel
================================================== -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php
$notun = new WP_Query(array(
'post_type' => 'bcarousel'
));
$indicator = -1;
while($notun->have_posts()) : $notun->the_post(); $indicator++ ?>
<li data-target="#myCarousel" data-slide-to="<?php echo $indicator; ?>"<?php if($indicator == 0) : ?> class="active" <?php endif; ?>></li>
<?php endwhile; ?>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php
$carousel = new WP_Query(array(
'post_type' => 'bcarousel',
));
$korim = 0;
while($carousel ->have_posts()) : $carousel ->the_post(); $korim ++ ?>
<?php if($korim == 1) : ?>
<div class="item active">
<?php else : ?>
<div class="item">
<?php endif; ?>
<div class="carousel-image">
<?php the_post_thumbnail(); ?>
<div class="carousel-caption">
<h1><?php the_title(); ?></h1>
<h2><?php the_content(); ?></h2>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<!-- Left and right Carousel Arrows -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div><!-- /.carousel -->
<!-- Images Feature Section
================================================== -->
<!-- Wrap the rest of the page in another container to center all the content. -->
<!-- <div class="container marketing"> -->
<!-- Three columns of text below the carousel -->
<section class="row content-region-1 pt40 pb40">
<div class="container">
<?php $loop = new WP_Query(array('post_type' => 'images_feature','orderby' => 'post_id', 'order' => 'ASC')); ?>
<?php while($loop->have_posts()) : $loop->the_post(); ?>
<div class="col-xl-2 col-centered">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
}
?>
<p><?php the_title(); ?> »</p>
<?php endwhile; ?>
</div><!-- /.col-lg-2 -->
</div>
</section><!-- /.row -->
<!-- Indianapolis Feature Section
================================================== -->
<section class="row" id="indy-glass">
<div class="container">
<div class="col-md-12">
<h2><?php echo $indianapolis_feature_title; ?></h2>
<hr />
<p class="lead"><?php echo $indianapolis_feature_body; ?></p>
</div>
<div class="col-md-12 text-center">
<p><a class="btn btn-danger" href="#" role="button">Learn More »</a></p>
</div>
</div>
</section>
<section class="row content-region-2 pt40 pb40" id="customer-testimonial">
<div class="container">
<div class="col-md-12">
<h1>What Our Customers Are Saying...</h1>
<p class="lead">We love Mirror Concepts! The team is professional and courteous and the new weightroom
mirrors look awesome!</p>
<cite>~ Jeff and Cindy Kivett</cite>
<p>Read More »</p>
</div>
</div>
</section>
<!-- Social Media Section
================================================== -->
<section class="row content-region-3 pt40 pb40" id="indy-glass">
<div class="container">
<div class="col-md-12 facebook-page">
<!-- If user uploaded an image -->
<?php if(!empty($social_media_image)) : ?>
<img src="<?php echo $social_media_image['url']; ?>" alt="<?php echo $social_media_image['alt']; ?>">
<?php endif; ?>
</div>
<h2><?php echo $social_media_title; ?></h2>
<hr />
<?php $loop = new WP_Query(array('post_type' => 'social_media_feature','orderby' => 'post_id', 'order' => 'ASC')); ?>
<?php while($loop->have_posts()) : $loop->the_post(); ?>
<div class="col-lg-2 col-centered">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
}
?>
<?php endwhile; ?>
</div><!-- /.col-lg-2 -->
<p>See more on Facebook »</p>
</div>
</section>
<?php get_footer(); ?>
In the style.css file you will see some selectors commented out because after turning this into WordPress dynamic they seem to be ineffectual.
Style.css file:
/*
Theme Name: Mirror and Glass Theme
Author: Daniel Cortes
Author URI: http://dancortes.com
Description: Theme developed for MediaFuel
Version: 1.0
*/
/* GLOBAL STYLES
-------------------------------------------------- */
/* Padding below the footer and lighter body text */
body {
background: url('/wp-content/themes/mirror_glass/assets/img/tile.jpg') top left repeat;
}
h1,h2,h3,h4,h5,h6 {
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
font-weight: bold;
font-family: "Comic Sans MS", cursive, sans-serif;
text-align: center;
}
a {
color: #000000;
}
a#gallery {
color: white;
font-size: 24px;
}
/*Non-Bootstrap CSS*/
.content-region-1, .content-region-2, .content-region-3 {
/*text-align: center;*/
/*float: right;*/
}
#customer-testimonial {
background: #3e4249;
color: white;
}
#showroom {
text-align: center;
}
.btn-danger {
padding: 10px 20px;
margin-bottom: 10px;
font-size: 20px;
border-radius: 10px;
}
.btn-default {
border: none;
background-color: transparent;
font-size: 24px;
}
/*.col-centered {
display: inline-block;
float: none;
}*/
.container {
max-width: 1020px;
}
.navbar-default {
background-color: white;
margin-bottom: 0;
}
.header {
padding-bottom: 20px;
border-bottom: 1px solid #e5e5e5;
}
.header h3 {
margin-top: 40px;
margin-bottom: 10px;
line-height: 40px;
}
.carousel-image {
margin: 0 auto;
}
p {
margin-top: 4px;
}
a.link {
font-size: 20px;
}
a:hover {
text-decoration: none;
}
a.btn-default:hover {
text-decoration: none;
}
.fa {
font-size: 98px;
margin-top: 10px;
margin-bottom: -10px;
opacity: 0.1;
}
.facebook-page {
position: relative;
line-height: -0.8;
}
/*.col-xl-2 {
margin: auto;
text-align: center;
width: 100%;
display: block;
}*/
#indy-glass {
background: white;
}
.footer {
padding-top: 19px;
text-align: center;
color: #777;
border-top: 1px solid #e5e5e5;
}
.content-region-4 {
background: #000000;
color: #ffffff;
}
.side-widget {
margin-bottom: 40px;
}
.side-widget h3 {
border-left: 5px;
padding-left: 10px;
margin-bottom: 15px;
}
/*==== MEDIA QUERIES ====*/
#media screen and (max-width: 991px) {
.img-rounded {
margin: 12px;
}
}

Add space in between images

On my front page I have three posts in a row that are spread across the full width of the page. I want to add a padding of 30px to the left. However my problem is then that at the beginning of each row of images there is a padding of 30px. I want it so that technical there is only a padding to the left and right 30px of the middle image, so the outer two images are always touching the end of the screen. I tried using :first-child to then take away the padding, however since I have the posts in a loop it did not work, and removed padding from all three images. Does anyone have a solution?
what it looks like...
<article <?php post_class( 'col-md-4' ); ?>>
<div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div></article>
.medium-front-thumbnail {
max-width: 100%;
height: auto;
position: relative;
margin: 0 auto;
align-items: flex-end;
display: block;
float: left;
}
.front-thumbnail-image {
padding-left: 30px !important;
}
.col-md-4 {
padding: 0 0 0 0 !important;
margin-bottom: 100px;
background-color: red;
}
my entire front-page.php
<?php
/*
* Template Name:
*/
get_header();
get_template_part ('inc/carousel');
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax">
<?php
$i = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?>
<article <?php post_class( 'col-md-12' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</article><?php
} else { // Small posts ?>
<article <?php post_class( 'col-md-4' ); ?>>
<div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div>
<a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</article>
<?php
}
$i++;
}?>
</div>
<?php if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();
you can use :nth-child(2) to target the middle div.
.grid > div:nth-child(2) {
padding: 0 30px;
}
.grid > div {
float: left;
}
.grid {
background: red;
overflow: auto;
display: inline-block;
}
img {
display: block;
max-width: 100px;
}
<div class="grid">
<div><img src="https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg"></div>
<div><img src="https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg"></div>
<div><img src="https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg"></div>
</div>
On the code you've provided I can see you uses Flexbox. To the container of the images try to add justify-content: space-between. That should only add space between the images.
.front-thumbnail-image {
display: flex;
justify-content: space-between;
background: red;
}
<article class='col-md-4'>
<div class="front-thumbnail-image">
<img src="https://getuikit.com/v2/docs/images/placeholder_600x400.svg" height="120" />
<img src="https://getuikit.com/v2/docs/images/placeholder_600x400.svg" height="120" />
<img src="https://getuikit.com/v2/docs/images/placeholder_600x400.svg" height="120" />
</div>
</article>
Try this :
.grid img:not(:first-child) , .grid img:not(:last-child) {
padding: 0 10px 0 10px;
}
Full code :
img {
width: 100px;
height: 100px;
}
.grid {
background-color: red;
display: inline-block;
}
.grid img:not(:first-child) , .grid img:not(:last-child) {
padding: 0 10px 0 10px;
}
<div class="grid">
<img src="http://cdn.earthporm.com/wp-content/uploads/2014/10/animal-family-portraits-2__880.jpg">
<img src="http://onehdwallpaper.com/wp-content/uploads/2015/07/Abdorble-Animals-Desktop-Wallpapers-Pictures.jpg">
<img src="https://s-media-cache-ak0.pinimg.com/originals/b2/1e/c9/b21ec91754d33bb5de86c67c45482e12.jpg">
<img src="http://cisnerosnediadistribution.s3.amazonaws.com/media/images/reino_animal_-_trailer_image.png">
</div>

Can't figure out how to set color for specific div's in the loop

On the front page of my site I have 3 posts being pulled, with a div underneath each that is a link. I need each of the 3 divs to be a different color. New posts in this category are going to be displayed here as they are posted, but it will just display the most recent three. I need to make it so that the three "hear more >" divs are always the same color. Below are pics and the code.
How is it currently:
How I need it to be:
HTML:
<?php
$args = array(
'post_type' => 'success',
'posts_per_page' => 3,
'order' => 'ASC'
);
$query = new WP_Query($args);
?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="success-stories-div">
<div class="success-stories-text">
<p style="font-size: 120%;">Success Story</p>
<?php the_content(); ?>
</div>
<a href="<?php the_permalink(); ?>">
<div class="success-stories-link">Hear More >
</div>
</a>
</div>
<?php endwhile; wp_reset_query(); ?>
CSS:
.success-stories .success-stories-link {
margin-top: 1em;
width: 465px;
height: 50px;
background-color: #F4B147;
padding: 12px 0 0 15px;
}
you can use selector
example:
<style>
div{
margin-top: 1em;
width: 465px;
height: 50px;
padding: 12px 0 0 15px;
}
div.success-stories-link:nth-child(1) {
background: green;
}
div.success-stories-link:nth-child(2) {
background: yellow;
}
div.success-stories-link:nth-child(3) {
background: red;
}
</style>
<div class="success-stories-link">1</div>
<div class="success-stories-link">2</div>
<div class="success-stories-link">3</div>
I think that the problem is that you are not calling the other colors: I would try something like this: What I am doing here is that I am creating a variable $i and make it $i=0 then inside the while loop I increment $i and so I can add a number at the end of the css class and it will look like this:
class="success-stories-link<?php echo $i; ?>"
<?php
$args = array(
'post_type' => 'success',
'posts_per_page' => 3,
'order' => 'ASC'
);
$query = new WP_Query($args);
?>
<?php $i = 0;
while ($query->have_posts()) : $query->the_post(); ?>
<div class="success-stories-div">
<div class="success-stories-text">
<p style="font-size: 120%;">Success Story</p>
<?php the_content(); ?>
</div>
<a href="<?php the_permalink(); ?>">
<div class="success-stories-link<?php echo $i; ?>">Hear More >
</div>
</a>
</div>
<?php $i++; endwhile; wp_reset_query(); ?>
in the css I would add different background-color:
.success-stories .success-stories-link0 {
margin-top: 1em;
width: 465px;
height: 50px;
background-color: #F4B147;
padding: 12px 0 0 15px;
}
.success-stories .success-stories-link1 {
background-color: another-color;
}
.success-stories .success-stories-link2 {
background-color: another-color;
}
I haven't test this code. Also, I am looking at the pictures How I need to be:
Also, there might be a better solution to it...but this should save your life for now =)

wordpress PHP related posts last child

3 posts are displayed and under each of them there is a thin 1px border line - the last (3rd) post should not have this border. How to do that?
Code:
<?php
$args = array( 'numberposts' => 3 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<!-- TITLE -->
<div class="proponowanytitle">
<?php the_title(); ?>
</div>
<!-- DATE -->
<div class="proponowanydate">
<?php the_time('m F Y');?>
</div>
<?php endforeach; ?>
CSS:
.proponowanytitle {
color:#34a694;
font-size:13px;
font-weight:400;
padding:15px 0 0 0;
margin:0;
}
.proponowanydate {
color:#999a9b;
font-size:14px;
font-weight:400;
padding:0 0 15px 0;
margin:0;
border-bottom:1px solid #e2e2e3;
}
.proponowanydate:last-child {
color:#999a9b;
font-size:14px;
font-weight:400;
padding:0 0 15px 0;
margin:0;
}
It doesn't work, i tried :not(:last-child) as well. Can anyone help me set the last-child?
As mentioned in the other comment, you can use the :last-child pseudo class. However, you need to make sure the last .proponowanydate is the last child of it's parent.
To make sure this happens, add in a wrap/container div:
HTML/PHP
<div class="container">
<?php
$args = array( 'numberposts' => 3 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<!-- TITLE -->
<div class="proponowanytitle">
<?php the_title(); ?>
</div>
<!-- DATE -->
<div class="proponowanydate">
<?php the_time('m F Y');?>
</div>
<?php endforeach; ?>
</div>
CSS
.proponowanytitle {
color:#34a694;
font-size:13px;
font-weight:400;
padding:15px 0 0 0;
margin:0;
}
.proponowanydate {
color:#999a9b;
font-size:14px;
font-weight:400;
padding:0 0 15px 0;
margin:0;
border-bottom:1px solid #e2e2e3;
}
.proponowanydate:last-child {
border-bottom: none;
}
Use the CSS :last-child selector after adding a parent element. See here.
.proponowanydate:last-child{
border-bottom: none;
}

Categories