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

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

顯示wordpress的第一個帖子

顯示wordpress的第一個帖子

PHP
滄海一幻覺 2021-05-13 14:17:08
我才剛剛開始使用wordpress,所以對于你們中的一些人來說,我的問題聽起來有點簡單,但是我找不到如何使它起作用的方法。我正在wordpress上構建博客頁面,我想以不同于其他文章的方式顯示第一篇文章,然后顯示一些靜態文本,然后繼續第二篇文章的帖子循環。我的第二個問題是我需要將縮略圖以絕對位置放置在div內(現在,當我調整瀏覽器大小時,它正在怪異地縮?。?。在我的引導程序原型上,我將圖像放置在div中,并使用background屬性導入了圖像。用wordpress替換該行為的最佳方法是什么?我為此做了一個簡單的草圖:我已經搜索了stackoverflow并嘗試了一些代碼片段,但我無法使它們全部正常工作。順便說一句,我正在使用UNDERSTRAP主題作為樣板。
查看完整描述

3 回答

?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

您需要忘記默認的WordPress循環。請改用WP_Query類查詢您的帖子。


$query = new WP_Query([

   ‘post_type’ => ‘post’,

   ‘posts_per_page => -1,

]);


 // Get the first post

$firstElement = array_shift($query->posts);


 // Get the other posts exect first element

$otherPosts = $query->posts;

現在,您需要在模板中循環以創建帖子網格。



查看完整回答
反對 回復 2021-05-28
?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

此過程是將標簽的類別更改為全角。有很多方法可以做到這一點,但我發現這很簡單。首先,從content.php中取出標簽并將其放在index.php中。這是為了檢查并更改article標簽內的類。


<div class="site-main" id="main">

<div class="row no-gutters">

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


    <?php /* Start the Loop */ ?>



    <?php 

    // Required variables

    $post = $posts[0]; $c=0; ?>


    <?php while ( have_posts() ) : the_post(); ?>



        <article class="col p-0 <?php $c++; if($c == 1) { echo 'col-12'; }else{ echo 'col-4'; } ?>" <?php post_class(); ?> id="post-<?php the_ID(); ?>"> 


            <?php


            /*

            * Include the Post-Format-specific template for the content.

            * If you want to override this in a child theme, then include a file

            * called content-___.php (where ___ is the Post Format name) and that will be used instead.

            */

            get_template_part( 'loop-templates/content', get_post_format() );

            ?>


        </article>



    <?php endwhile; ?>


<?php else : ?>


    <?php get_template_part( 'loop-templates/content', 'none' ); ?>


<?php endif; ?>


</div>



查看完整回答
反對 回復 2021-05-28
  • 3 回答
  • 0 關注
  • 180 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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