亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

If else 特定類別發布 wordpress

If else 特定類別發布 wordpress

PHP
qq_笑_17 2022-11-04 16:19:44
我正在嘗試制作 if else 腳本,但無法正確處理。我想要一個帶有左側縮略圖和右側文本的帖子,當我在該類別中發布另一個帖子時,我想要右側縮略圖和左側文本。到目前為止,這是我的代碼:<div class="row">        <?php if (query_posts('category_name=news'))            if (have_posts()) : while (have_posts()) : the_post(); ?>                <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">                    <?php                    if ($wp_query->current_post % 2) {                        echo "<div class='image-test'>";                        the_post_thumbnail('thumbnail');                        echo "</div>";                        echo "<div class='tekst-rechts'>";                        the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');                        the_content();                        echo "</div>";                    }                    ?>                </div>            <?php endwhile; ?>        <?php else : ?>            <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">                <?php                //echo "Current item is ". (($wp_query->current_post % 2) ? "oneven" : "even");                //the_title( '<h1 class="entry-title">', '</h1>' );                the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');                the_post_thumbnail('');                the_content();                ?>            </div>        <?php endif; ?>        <?php wp_reset_query(); // reset the query         ?>    </div>
查看完整描述

1 回答

?
MM們

TA貢獻1886條經驗 獲得超2個贊

你可以通過 CSS FlexOrder:nth-child()選擇器來做到這一點。


HTML(包含 php):


    <div class="row">


        <?php if (query_posts('category_name=news'))

            if (have_posts()) : while (have_posts()) : the_post(); ?>

                <div <?php post_class('post-contents'); ?> id="post-<?php the_ID(); ?>">

                    <?php

                        echo "<div class='image-test'>";

                        the_post_thumbnail('thumbnail');

                        echo "</div>";

                        echo "<div class='tekst-rechts'>";

                        the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');

                        the_content();

                        echo "</div>";

                    ?>

                </div>


            <?php endwhile; ?>


        <?php else : ?>


            <p>No posts!</p>


        <?php endif; ?>


        <?php wp_reset_query(); // reset the query ?>

    </div>

CSS:


    .post-contents {

      display:flex;

      flex-flow: row wrap;

      justify-content: space-between;

      align-items: center;

    }


    .post-contents:nth-child(odd) .image-test {

      order: 2;

    }


    .post-contens:nth-child(odd) .entry-title {

      order: 1;

    }

不要忘記在 post_class() 函數中添加 post-contents 類。


查看完整回答
反對 回復 2022-11-04
  • 1 回答
  • 0 關注
  • 97 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號