无法在一行帖子中添加margin-right

时间:2016-08-23 13:31:38

标签: php css wordpress

现在我连续3个帖子,下一行有3个帖子,下一行有1个帖子,依此类推。我试图在连续3个帖子之间添加空格。每次我添加css margin-right:25px;到.col-mod-4 {它增加了空间,但是1个帖子被排掉了,而我有3行2个帖子。有没有人有任何解决方案? (我附上了一个带有问题截图的保管箱链接)

https://www.dropbox.com/sh/fbi17l2ortzpqkk/AACDm2XIcvJDjouAb0zPilfVa?dl=0

这是我的index.php



<?php
/*
 * Template Name: learningwordpress
 */
 
get_header();
 
$i = 0;
 
$args = array(
    'posts_per_page' => 14,
    'paged' => 1
);
 
$the_query = new WP_Query($args);
 
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
 
        if( $i %2 == 1 ) {
                   $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>      
            <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>
 <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>

 <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>      
            <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>
 <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>
            <?php

        }
        else {
         $the_query->the_post(); ?>
            <article class="post col-md-12">
                <?php the_post_thumbnail('large-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>
            <?php
        }
        ?>
        <?php
        $i++;
    }
}
else {
    echo '<p>Sorry, no posts matched your criteria.</p>';
}
get_footer();
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

尝试填充右边而不是边距右边