Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: How i can integrate php with css?

VenusSModzHD free asked 7 years ago


Im triying to make a wordpress template and i choose this style for my post but i dont now how to include the post thumbnail in this card type?

 

<!-- Card -->
<div class="card card-image" style="background-image: url("<?php the_post_thumbnail( 'full', array( 'class'=> 'img-fluid z-depth-2')); ?>"); ">

<!-- Content -->
<div class="text-white text-center d-flex align-items-center rgba-black-strong py-5 px-4">
<div>
<h5 class="pink-text"><i class="fa fa-pie-chart"></i> Marketing</h5>
<h3 class="card-title pt-2"><strong>This is card title</strong></h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellat fugiat, laboriosam, voluptatem,
optio vero odio nam sit officia accusamus minus error nisi architecto nulla ipsum dignissimos.
Odit sed qui, dolorum!.</p>
<a class="btn btn-pink"><i class="fa fa-clone left"></i> View project</a>
</div>
</div>
<!-- Content -->
</div>
<!-- Card -->


Witold Tkaczyk free answered 7 years ago


Hi, There are two solutions: 1. you can use $post_thumbnail_url;:
 $post_thumbnail_id = get_post_thumbnail_id();
 $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );?>
 
 <div class=”card card-image img-fluid z-depth-2” style=”background-image: url(“<?php echo $post_thumbnail_url ?>”); “>
2. create your own post image size:
add_image_size( 'custom-size', 220, 180 );
<?php the_post_thumbnail( ‘full’, array( ‘class’=> ‘img-fluid z-depth-2’)); ?>
That should solve your problem. FYI the_post_thumbnail( ‘full’, array( ‘class’=> ‘img-fluid z-depth-2’)) returns already constructed <src> object. So if you var_dump(the_post_thumbnail( ‘full’, array( ‘class’=> ‘img-fluid z-depth-2’))), it shall return you this: <img src="..." class="alignleft wp-post-image" ...>

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: Other
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags