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

Minimize the gap between col-lg elements in responsive mode within Bootstrap

My website is built using Bootstrap 4 and the following is the HTML code: <div class="container"> <div class="row text-center "> <div class="col-lg-6">A</div> <div class="col-lg-6">B</div> </div> < ...

Place the emoji where the cursor is located

My query was already posted on stack overflow but unfortunately, I did not receive a response. The issue revolves around 2 links named "add emoji 1" and "add emoji 2". As mentioned earlier, my question can be accessed here: Insert smiley at cursor positio ...

Influencing various classes when :active is triggered

I encountered a challenge while working on an HTML project. I included a checkbox that should highlight all text input fields when checked. However, I'm facing an issue where some of the input fields within tables are not being affected by my code. An ...

Align two containers centrally using absolute positioning inside a division

I am looking for a way to centrally align two "boxes" within a div using CSS. These boxes are positioned absolutely. For reference, here is the JSFiddle link: http://jsfiddle.net/p4sA3/8/ Is there a method to achieve this alignment without specifying spe ...

Having trouble with the <img> tag on CodeSandbox.io? Image not loading properly

I've been attempting to insert an image using the <img> tag on CodeSandbox.io. However, each time I try to do so, it fails to display and defaults to the alt tag (Shows Mountain). The goal is to load an image from the same folder as the file th ...

The Bootstrap 5 Accordion Content is not Showing Up

In my current project in vscode, I am using Bootstrap 5 to develop a website. Specifically, I am working on creating an accordion feature with Bootstrap 5. However, I encountered an issue where the accordion body does not show up when clicking on the acc ...

The sticky table header is being covered by a disabled HTML button, while the active buttons are not visible

I'm currently working on a website using Bootstrap 5 as my framework. The issue I'm facing is that when scrolling down the page and keeping the table header stuck to the top, the disabled button ends up showing over the header. I attempted to us ...

What is the main purpose of using the CSS transform:translate() property?

When CSS3 introduced animations with transition properties, it gave developers two main ways to change the position of an element. The first method involves setting the element's position as absolute and adjusting the left, right, top, and bottom prop ...

Utilize the splice function when resizing the window based on specific breakpoints

On a series of div elements, I have implemented some JS/jQuery code that organizes them by wrapping every three elements in a container with the class .each-row. <div class="element"></div> <div class="element"></div> <div class ...

Issues with Bootstrap Carousel Slide Show functionality in FireFox

I have implemented a Bootstrap-5 Carousel Slide Show for the website banner. It is functioning correctly in Google Chrome, but there seems to be an issue when viewed in Firefox. The Firefox browser version I am using is 90.0.2 (64-bit). Upon inspecting the ...

What is the difference between using min-height in vh versus % for the body tag

I'm trying to understand a code where the min-height of the body element is set to 100vh after previously defining the height of the html element as 100%. Why is there a need for this specific sequence? body { position: relative; overflow: hidd ...

Position an element with absolute positioning to the right edge of a relative element

I have a situation where I need to align the end of a position absolute element with the end of a relative element, but the relative element's width is not fixed and may vary based on content. This scenario arises as I am creating a custom dropdown m ...

Customizing WordPress permalinks with .htaccess

I have recently customized the structure of post permalinks to be /post/%post_id% using the permalink settings in the Admin panel. Now, I am looking to rewrite the permalinks for categories, tags, and author pages as follows: Categories From /post/categ ...

What is the best way to create a triangle shape that is responsive to elements?

I'm trying to make a background shape with a triangle inclusion using CSS. I want it to be responsive to all screen sizes, but I'm having some trouble. Any tips on how to achieve this? header { width: 100%; height:150px; background: #eee; } m ...

Use PHP to highlight the row that has been selected in an HTML table

I am currently working on a project where I have styled multiple HTML tables on my website using alternating gray and white bands. Now, my goal is to highlight the selected row in a darker shade of gray. I have experimented with various solutions, and the ...

What causes the source code of a website to change when accessed from various browsers?

When analyzing the source code of bartzmall.pk using various browsers, it reveals different classes being added to the html tag for each browser. For Firefox: <html class="firefox firefox53 otherClasses"> For Chrome: <html class="webkit chrome ...

Positioning an image so that it is perfectly aligned on top of another image that is centered

http://jsfiddle.net/Weach/1/ The issue at hand involves a background image created using CSS. This image has been center aligned both horizontally and starting from the top, as visible in the provided JSFiddle link. Specifically, there is another image t ...

Stylish CSS animation enhancing an image

Can a flash effect like the one in this image be created using only CSS? I attempted to use -webkit-filter, but it did not produce satisfactory results. ...

Issue with JavaScript not executing upon clicking the submit button on a form within the Wordpress admin page

In the admin pages of my Wordpress installation, I have created an HTML form. My goal is to validate the data inputted when the submit button is pressed using a Javascript function. If the data is not correctly inserted, I want alerts to be displayed. Desp ...

The justify-content-sm-center behavior in Bootstrap seems to be malfunctioning

I am facing an issue with justify-content-sm-center in Bootstrap 5. It is not functioning as intended when trying to center a specific div on smaller screens (below 578px). I have applied the justify-content-sm-center class to the div, but it does not work ...