如何在单个PHP循环代码中使用2 div类

如何在单个PHP循环代码中使用2 div类,php,html,css,wordpress,while-loop,Php,Html,Css,Wordpress,While Loop,我正在将一个主题从HTML模板转换为WordPress主题的动态 我已经创建了一些自定义的帖子类型,如,服务,幻灯片,团队等等。 现在,我的问题是我不能像HTML模板那样设计服务。因为,模板使用2 DIV类。其中一个是“服务wow fadeInUp”,另一个是“服务wow fadeInDown” 示例: 文本1=服务wow fadeInUp 文本2=服务wow fadeInDown 文本3=服务wow fadeInUp 文本4=服务wow fadeInDown *继续* 但是,当我使用PHP代码

我正在将一个主题从HTML模板转换为WordPress主题的动态

我已经创建了一些自定义的帖子类型,如,服务,幻灯片,团队等等。 现在,我的问题是我不能像HTML模板那样设计服务。因为,模板使用2 DIV类。其中一个是“服务wow fadeInUp”,另一个是“服务wow fadeInDown

示例:
文本1=服务wow fadeInUp
文本2=服务wow fadeInDown
文本3=服务wow fadeInUp
文本4=服务wow fadeInDown
*继续*

但是,当我使用PHP代码在index.PHP中显示服务(自定义post类型)时,它只有一个DIV类。我不知道如何在单个PHP代码中使用2div类来显示我的自定义帖子类型。 我是PHP语言的新手。如果有人能帮我解决这个问题,并给我一些关于如何做的描述,这将对我非常有帮助。 我的代码如下:

functions.php

index.php


...
如果你注意到,你会发现那里只有一个div类可用。如何在其中添加第二个div类?
请帮帮我

@skobaljic上面的评论是一个(可以说是更简洁的)解决方案,但是如果您想保留现有的CSS类,并完全用PHP进行替换,下面介绍如何做到这一点

基本上,在变量中保留交替类名,并在循环的每次迭代中更改它:

<div class="col-sm-3">

<?php
    $thservices = new WP_Query(array(
        'post_type' => 'tservices',
        'order'   => 'ASC'
    ));
?>
<?php while($thservices->have_posts()) :
    $thservices->the_post();
    if($divclass == "fadeInUp") { $divclass = "fadeInDown"; }
    else { $divclass = "fadeInUp"; }
    ?>

    <div class="service wow <?=$divclass?>">
        <div class="service-icon"><?php echo get_post_meta($post->ID, 'faicon', true); ?></i></div>
        <h3><?php the_title(); ?></h3>
        <?php the_content(); ?>...

        <a class="big-link-1" href="services.html">Read more</a>
    </div>

<?php endwhile; ?>

</div>


@skobaljic在上面的评论是一个(可以说是更简洁的)解决方案,但是如果您想保留现有的CSS类,并完全用PHP进行替换,下面介绍如何做到这一点

基本上,在变量中保留交替类名,并在循环的每次迭代中更改它:

<div class="col-sm-3">

<?php
    $thservices = new WP_Query(array(
        'post_type' => 'tservices',
        'order'   => 'ASC'
    ));
?>
<?php while($thservices->have_posts()) :
    $thservices->the_post();
    if($divclass == "fadeInUp") { $divclass = "fadeInDown"; }
    else { $divclass = "fadeInUp"; }
    ?>

    <div class="service wow <?=$divclass?>">
        <div class="service-icon"><?php echo get_post_meta($post->ID, 'faicon', true); ?></i></div>
        <h3><?php the_title(); ?></h3>
        <?php the_content(); ?>...

        <a class="big-link-1" href="services.html">Read more</a>
    </div>

<?php endwhile; ?>

</div>


不想回答,因为这不是php/WP问题,而是css问题。不要添加两个类,而是将CSS更改为address
.service.wow:nth child(2n)
.service.wow:nth child(2n+1)
而不是
fadeInUp
fadeInDown
。不想回答,因为这不是php/WP问题,而是CSS问题。不要添加两个类,而是将CSS更改为address
.service.wow:nth child(2n)
.service.wow:nth child(2n+1)
而不是
fadeInUp
fadeInDown
<div class="col-sm-3">

<?php
    $thservices = new WP_Query(array(
        'post_type' => 'tservices',
        'order'   => 'ASC'
    ));
?>
<?php while($thservices->have_posts()) :
    $thservices->the_post();
    if($divclass == "fadeInUp") { $divclass = "fadeInDown"; }
    else { $divclass = "fadeInUp"; }
    ?>

    <div class="service wow <?=$divclass?>">
        <div class="service-icon"><?php echo get_post_meta($post->ID, 'faicon', true); ?></i></div>
        <h3><?php the_title(); ?></h3>
        <?php the_content(); ?>...

        <a class="big-link-1" href="services.html">Read more</a>
    </div>

<?php endwhile; ?>

</div>