Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress发布奇偶Li布局_Php_Jquery_Css_Wordpress_Html Lists - Fatal编程技术网

Php Wordpress发布奇偶Li布局

Php Wordpress发布奇偶Li布局,php,jquery,css,wordpress,html-lists,Php,Jquery,Css,Wordpress,Html Lists,我正在处理一个自定义主题,在其中一个页面上,我需要按如下方式设置帖子页面的样式: 灰色框为图像,红色框为内容。我可能需要使用奇数/偶数Li/Ul伪类/选择器,但我不知道如何做到这一点 有谁能给我一个启动它的方法吗?我想在UL上使用奇偶伪类来更改divs的名称,但是我不知道该怎么做,也不知道从哪里开始 谢谢 编辑:我想可能是奇数/偶数选择器与jquery prepend/append相结合 Edit2:这就是我所拥有的,但是它首先显示了所有的赔率,然后是所有的平局,而不是交替显示 PHP: 由于

我正在处理一个自定义主题,在其中一个页面上,我需要按如下方式设置帖子页面的样式:

灰色框为图像,红色框为内容。我可能需要使用奇数/偶数Li/Ul伪类/选择器,但我不知道如何做到这一点

有谁能给我一个启动它的方法吗?我想在UL上使用奇偶伪类来更改divs的名称,但是我不知道该怎么做,也不知道从哪里开始

谢谢

编辑:我想可能是奇数/偶数选择器与jquery prepend/append相结合

Edit2:这就是我所拥有的,但是它首先显示了所有的赔率,然后是所有的平局,而不是交替显示

PHP:


由于您处于循环中,您可以使用内置循环计数器(
$wp\u query->current post
)将不同的类添加到所有赔率或所有偶数或两者中

不需要运行两个循环。下面是一个例子,我如何在我的网站上使用它来创建两个帖子栏

<?php if ( have_posts() ) : ?>

<?php while ( have_posts() ) : the_post();  ?>
        <?php /* Start the Loop */ ?>

        <div class="entry-content-<?php if( $wp_query->current_post%2 == 1 ){ echo ' left-post';}else{ echo ' right-post';} ?>">
        <?php get_template_part( 'content', get_post_format() ); ?>
        </div>

<?php endwhile; ?>


是的,我已经在原始帖子中发布了我的代码,谢谢如果你有一个你需要的布局(例如,左边的图像,右边的文本),并且这只是重复,你可以使用
:nth child(2n)
伪选择器,并使用css使图像浮动(或绝对定位它们)在另一侧。这样,每个其他元素都会有这样的定位。问题是,我使用一个Div作为图像,一个Div作为信息,所以我不确定这是否会起作用?如果它们每次都在具有相同类的包装器中,那么就以该包装器为目标。这样做很好,这是一个很好的干净的实现方法,谢谢。这是一个处理循环的更干净的方法,但是我不确定我是否可以在我当前的代码中实现它。我刚试了一个小时,没能让它工作。基本上,文章中的图像集在一个Div中,内容(文本/标题)也在一个Div中。这两个Div位于一个容器行中,我调整每个Div的宽度,以从屏幕截图中显示布局。如果你认为我仍然可以实现这一点,请随时告诉我,谢谢你的时间!我的荣幸。很高兴我能帮忙:-)
<?php if ( have_posts() ) : ?>

<?php while ( have_posts() ) : the_post();  ?>
        <?php /* Start the Loop */ ?>

        <div class="entry-content-<?php if( $wp_query->current_post%2 == 1 ){ echo ' left-post';}else{ echo ' right-post';} ?>">
        <?php get_template_part( 'content', get_post_format() ); ?>
        </div>

<?php endwhile; ?>
<?php if ( have_posts() ) : ?>

    <?php while ( have_posts() ) : the_post();  ?>
    <?php /* Start the Loop */ 

        if($wp_query->current_post%2 == 1 ) { ?>

            <div class="section group">

                <div class="col span_1_of_2 blue doubleheight">

                    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>

                </div>

                <div class="col span_1_of_3_30 blue doubleheight">
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <div class="post-text">
                        <?php the_excerpt(); ?>
                    </div>
                </div>


            </div>

        <?php }else{ ?>

            <div class="section group">
                <div class="col span_1_of_3_30 blue doubleheight">
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <div class="post-text">
                        <?php the_excerpt(); ?>
                    </div>
                </div>



                <div class="col span_1_of_2 blue doubleheight">
                    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
                </div>

            </div>

        <?php }

    <?php endwhile; ?>

 <?php endif; ?>