Creating a personalized layout for your WordPress posts with custom card designs

As a new developer diving into the world of WordPress, I am aiming to create a sleek and minimalistic grid/card layout for my website. Struggling to achieve this, I seek guidance on how to replicate the design seen in the following link: desired result

Here is the current state of my layout: current look

My attempt involved using Bootstrap and card components but failed because it did not maintain image consistency. Below is the code snippet I have been working on:

<?php





global $post;
    get_header();
    the_post();
    global $user_ID;
     ?>
    <section class="blog-header-container">
     <div class="container">
        <!-- blog header -->
        <div class="row">
            <div class="col-md-12 blog-classic-top">
                <h2><?php _e("Promotions",ET_DOMAIN) ?></h2>
                <form id="search-bar" action="<?php echo home_url() ?>">
                    <i class="fa fa-search"></i>
                    <input type="text" name="s" placeholder="<?php _e("Search by city",ET_DOMAIN) ?>">
                </form>
            </div>
        </div>
        <!--// blog header  -->
    </div>
</section>
<section >
    <?php query_posts('post_type=promotions&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>

    <?php 
    // Get total posts
    $total = $wp_query->post_count;

    // Set indicator to 0;
    $i = 0;
    ?>

    <?php while( have_posts() ): the_post(); ?>

        <?php if ( $i == 0 ) echo '<div class="row container" style="margin-top:25px">'; ?>


        <div class="col-sm-3" style="margin:40px">

        <p class="text-align:center">
            <?php if ( has_post_thumbnail() ) : ?>
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'my-custom-size' ); ?></a>
            <?php endif; ?>
        </p>

        <strong><p><a style="color: black;font-size:12" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p></strong>

        <p>Location: <?php echo get_post_meta($post->ID, 'promo_location', true); ?></p>
      <p>Expires: <?php echo get_post_meta($post->ID, 'promo_expiration', true); ?></p>       
 <span class="avatar-author">

                                Offered By: <a style="color: black;" href="<?php echo get_author_posts_url($post->post_author ); ?>"><?php the_author();?></a>

                            </span>


        </div><!-- col -->

        <?php $i++; ?>

        <?php

        if ( $i == $total ) { 
            echo '</div>';
        } else {

            if ( $i % 3 == 0 ) {
                echo '</div><div class="row">';
            }
        }
        ?>

    <?php endwhile; ?>

</div><!-- container -->
</section>
<?php



get_footer();

?>

Your help is greatly appreciated!

Answer №1

This method demonstrates how to create uniform-height tiles with image headers that fill a flex container. The key elements are within the container:

display: flex;
justify-content: space-between;
flex-wrap: wrap;

Adjusting the margin and padding values is crucial for achieving the desired spacing.

.tiles {
  padding: 0 20px;
  background: #eee;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.tile {
  width: calc(33.3% - 20px);
  background: #fff;
  margin: 10px 0;
}

.tile__header-image {
  height: 150px;
  background-position: center;
  background-size: cover;
  background-color: #666;
}

.tile__content {
  padding: 10px;
}

.tile__content h5 {
  margin: 0 0 6px;
}

.tile__content ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tile__content li {
  display: inline-block;
  font-size: .8em;
  color: #999;
}

.tile__content li::after {
  content: " - "
}

.tile__content li:last-child::after {
  content: "";
}
<div class="tiles-wrapper">
  <div class="tiles">
    <div class="tile">
      <div class="tile__header-image" style="background-image: url( https://loremflickr.com/320/240 );"></div>
      <div class="tile__content">
        <h5>My Title Here</h5>
        <ul>
          <li>Tag 1</li>
          <li>Tag 2</li>
          <li>Tag 3</li>
        </ul>
      </div>
    </div>

    <div class="tile">
      <div class="tile__header-image" style="background-image: url( https://loremflickr.com/320/242 );"></div>
      <div class="tile__content">
        <h5>My Title Here</h5>
        <ul>
          <li>Tag 1</li>
          <li>Tag 2</li>
          <li>Tag 3</li>
        </ul>
      </div>
    </div>

    <div class="tile">
       <div class="tile__header-image" style="background-image: url( https://loremflickr.com/320/243 );"></div>
      <div class="tile__content">
        <h5>My Title Here</h5>
        <ul>
          <li>Tag 1</li>
          <li>Tag 2</li>
          <li>Tag 3</li>
        </ul>
      </div>
    </div>

    <div class="tile">
      <div class="tile__header-image" style="background-image: url( https://loremflickr.com/320/244 );"></div>
      <div class="tile__content">
        <h5>My Title Here</h5>
        <ul>
          <li>Tag 1</li>
          <li>Tag 2</li>
          <li>Tag 3</li>
        </ul>
      </div>
    </div>

    <div class="tile">
      <div class="tile__header-image" style="background-image: url( https://loremflickr.com/320/245 );"></div>
      <div class="tile__content">
        <h5>My Title Here</h5>
        <ul>
          <li>Tag 1</li>
          <li>Tag 2</li>
          <li>Tag 3</li>
        </ul>
      </div>
    </div>

    <div class="tile">
       <div class="tile__header-image" style="background-image: url( https://loremflickr.com/320/246 );"></div>
      <div class="tile__content">
        <h5>My Title Here</h5>
        <ul>
          <li>Tag 1</li>
          <li>Tag 2</li>
          <li>Tag 3</li>
        </ul>
      </div>
    </div>

  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to expand the subcategories within a list?

I have successfully implemented a script to open my hamburger menu. However, I am facing an issue with subitems as some list items contain them. How can I modify the script to ensure that the subitems expand when clicked instead of just hovering? functi ...

Apply the CSS style specifically to the initial row in the table

Is there a way to target the first row of a table with a different tr class using CSS? <div id="right"> <table> <tbody> <tr class="head"> <td >Date</td><td>Info</td><td>More</td> </tr> ...

CSS - Apply a captivating background to specific columns within a grid layout

Wow, I'm really struggling with CSS and this particular issue has me perplexed. I need to add background colors to specific columns but not all of them. The problem is that the padding gets messed up when I do this. Imagine having a headache while try ...

How to target a class with a specific number in CSS selectors

My mobile hybrid application is built with Sencha Touch 2 and requires some customization based on the iOS version it's running on. In my Sass stylesheet, I originally had the following selector: .x-ios-7 { /* add iOS7 customizations here */ } How ...

Challenge with organizing space within a nested layout of flexboxes and CSS grids

Is it possible for my aside element and div.content to evenly split the available space in the container? Additionally, should the grid within div.content take up all the vertical space? The issue I'm encountering is that grid items aren't able ...

Ways to expand the border horizontally using CSS animation from the middle

Currently, I am experimenting with CSS animation and I have a query regarding creating a vertical line that automatically grows in length when the page is loaded. I am interested in making the vertical line expand from the center in both upward and downwar ...

Create a CSS menu that remains fixed at the top of the page and highlights the current submenu as

When explaining a concept, I find it easier to include a drawing to ensure clarity. https://i.stack.imgur.com/IChFy.png My goal is to keep the menu at the top of the page after scrolling past the header. https://i.stack.imgur.com/3fzJ6.png Using Bootst ...

Having a problem with the hover effect on the navbar component

Whenever I hover over the individual links, I notice that the color change doesn't extend all the way up. I have a feeling there is a more efficient way to achieve this than my current approach. Any assistance would be greatly appreciated! HTML: < ...

creating an interactive element that seamlessly integrates with a dynamic background image slideshow

Struggling to make this work correctly as a newbie in javascript. I need the background image to slide upon hover and stay active on its selected div when clicked. The html, css, and javascript I have currently work fine - when the user clicks on a div, a ...

Having trouble getting the jquery tabify plugin to work properly

I've put in a lot of effort and double-checked everything, but for some reason this tabify function just won't work. I have gone through my code 100 times but still can't seem to pinpoint the error. Here is the code I am working with: <! ...

Adjust the font size within a container using HTML code, no CSS required

Is it possible to directly change the TextSize and TextColor within the HTML Document? I need it to be within this specific box (same class) because of the background color. However, the text size always remains the same. The HTML line is: Which button re ...

Could there be an issue with the directory path for the file?

https://i.stack.imgur.com/m8F9y.pngThe background-url() function was utilized to set the background screen to PurpleCloud.png. Despite multiple attempts, the image is still not being displayed. What could be the issue? Even after understanding file path w ...

Attempting to link two JavaScript files, however, only one of them is functioning correctly

I'm currently experiencing an issue with my HTML page that involves calling two JS files for two different image sliders on the same website page. One slider works perfectly fine while the other does not. I'm confused as to whether it's perm ...

In Bootstrap 5, the anchor tag is causing a shift in the background color of surrounding tags upon being clicked

Why does clicking on an anchor tag temporarily change the background of other tags that weren't clicked? What am I doing wrong? https://i.stack.imgur.com/ZKlUT.png Check out the code below: <nav class="navbar navbar-expand-lg navbar-light bg- ...

Excess space appearing to the right of the text box in Internet Explorer 9 standards mode and Google Chrome

Looking for help on how to eliminate the space between the right side of an input textbox and a red border? Check out these examples: IE: http://jsfiddle.net/fQHGA/ <div style="float:left;border:1px solid red"> <label style="float:left">a ...

Guide on how to implement AJAX functionality for the shopping cart items and total amount

I am currently working on updating the cart items and total on my website using ajax whenever a user clicks on "add to cart". I have implemented the following code in the function.php file of my WordPress site: add_filter('wp_nav_menu_items',&ap ...

When adding a border radius to an iframe, you'll notice delicate curved lines appearing on all four corners

I have implemented material UI's CardMedia component to display an Iframe with a embedded youtube link. To achieve rounded corners for the iframe, I set the border-radius to 30px. Although it successfully rounds the corners, it also introduces thin li ...

Achieving unique horizontal and vertical spacing in Material UI Grid

In my current Material UI setup, I have set spacing in the Grid Container to space Grid Items vertically. While this works well on larger screens, it causes awkward horizontal spacing between Grid Items on mobile devices. <Grid container spacing={24}> ...

Webkit feature: Rounded border image overlay

One issue arises when applying a rounded border to an image in webkit browsers as the border ends up hidden behind the image. CSS img { border: 10px solid #000; border-radius: 100%; } HTML <img src="http://25.media.tumblr.com/tumblr_mbje ...

What is the reasoning behind the repetitive use of @media (max-width: 767px) in the Twitter Bootstrap

Why is the media query @media (max-width: 767px) repeated in the bootstrap-responsive.css file? To find out, you can view the file by visiting ...