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

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

如何防止砌體網格中“獲取相關內容”的重疊?

如何防止砌體網格中“獲取相關內容”的重疊?

PHP
哈士奇WWW 2023-09-22 17:05:16
我在 single.php 頁面上有一個有效的 '$lated = get_posts' 砌體。我還添加了一個懸停覆蓋層,以便當用戶將鼠標懸停在縮略圖上時,會出現一個透明的覆蓋層以及描述(標題名稱、類別和昵稱)。我面臨的問題是,當我將鼠標懸停在一個相關帖子縮略圖上時,每個帖子都會出現疊加層(疊加層被拉伸,不會單獨出現)。我也嘗試過調用描述,但它只是調用我正在查看的當前帖子(例如當前的 single.php 標題說 Snow ,當我將鼠標懸停在第一個相關帖子時,它還會調用 Snow 的描述),但是,如果您單擊第一個相關帖子縮略圖,它會將您帶到另一篇文章(它不會調用不同文章的描述)。<div class="related">    <h3>Related</h3>    <div class="js-masonry">        <div class="overlay">            <?php $related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'orderby' => 'rand', 'numberposts' => 3, 'post__not_in' => array($post->ID) ) );            if( $related ) foreach( $related as $post ) { setup_postdata($post); ?>            <a href="<?php the_permalink()?>"><?php the_post_thumbnail(array(300,300)); ?></a>            <?php } wp_reset_postdata(); ?>            <div class="posts">            <?php foreach((get_the_category()) as $category) {echo $category->cat_name . ' ';}?>          <h1><?php the_title();?></h1>          ————          <h4><?php the_author();?></h4>            </div>        </div>    </div></div>正如標題所述,如何通過將鼠標懸停在 WordPress 的 single.php 頁面上的“$related = get_posts”來提取一篇文章的正確描述和覆蓋?
查看完整描述

1 回答

?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

我通過正確地重新組織代碼解決了這個問題。


<div class="js-masonry">   

    <?php $args = array(

    'category__in' => wp_get_post_categories( get_queried_object_id() ),

    'posts_per_page' => 3,

    'orderby' => 'rand',

    'post__not_in' => array( get_queried_object_id() )

    );

    $the_query = new WP_Query( $args );

    if ( $the_query->have_posts() ) : ?>

    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <div class="item-masonry overlay">

    <a href="<?php the_permalink();?>">

        <div class="posts">

            <?php foreach((get_the_category()) as $category) {echo $category->cat_name . ' ';}?> 

            <h1><?php the_title();?></h1>

            ————

            <h4><?php the_author();?></h4>

        </div>

        <?php the_post_thumbnail(array(300,300)); ?>

    </div>

    </a>

    <?php endwhile; ?>

    <?php wp_reset_postdata(); ?>

    <?php endif; ?>

</div>


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 103 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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