【问题标题】:display odd div without image and even with images in wordpress在wordpress中显示没有图像的奇数div,甚至显示图像
【发布时间】:2015-11-21 11:06:58
【问题描述】:

想要隐藏特定的奇数 div 标签图像并显示偶数 div images.like

我有

div1 div2 div3 div4 div5 div6 div7 div8 div9 div10 div11 div12

现在,我想隐藏 div1、div5、div9 上的图像,并在 Wordpress 中使用 If 条件或 while 循环仅显示其他 div 标签图像。

我该怎么做..

这是我的代码。

<div class="default-team">
<div class="medium-3 columns">
    <h1><?php the_title();?></h1>

    <a href="<?php echo get_the_permalink();?>">Click to View Bio</a>       

</div>  
</div>


<?php  while ($query->have_posts()) : $query->the_post(); $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );   ?>

    <div class="team-inner">
        <div class="medium-3 columns">
            <div class="team-img">
                <img src="<?php echo $feat_image; ?>">
            </div>
            <div class="team-hover">
                <a href="#">View Bio</a>
            </div>             
        </div>
   </div>

我想隐藏“default-team”这些 div 标签图像并显示“team-inner”这些 div 标签图像。

【问题讨论】:

    标签: html css wordpress if-statement


    【解决方案1】:

    编辑 您可以使用nth-child(number) 选择器,而不是nth-of-type(odd) 选择器,查看代码示例以查看此操作会发生什么

    有关此选择器的更多信息,请查看here

    您的代码将如下所示:

    div:nth-child(4) img { /* This will select the 4th div and apply the given style to that div */
        display:none;
    }
    

    希望这会有所帮助!

    【讨论】:

    • 我只想隐藏第 1、第 5、第 9、第 13 和其余 div 标签显示。!就像我想在第一个 div 标签上隐藏图像然后显示下 3 个 div 标签图像然后隐藏第 5 个 div 图像并显示下 3 个 div 标签图像。!明白了吗?
    • 啊,给我一点时间解决,误会
    【解决方案2】:

    您可以使用以下代码。不需要创建任何类型的循环。

    div:nth-of-type(4n+1) img {display:none;}
    div:nth-child(4n+1) img{display:none;}             ///What ever you want
    

    如果还有错误,我在这里。

    【讨论】:

    • 完全正确,但我想在 php.ini 中进行。所以我需要它循环。
    • 用同样的类型你可以做循环,'4n+1'公式:D
    猜你喜欢
    • 2021-10-30
    • 2013-01-28
    • 2017-09-14
    • 1970-01-01
    • 2014-05-21
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多