簡體   English   中英

運行循環查詢時如何使 Div 在 Wordpress 中可點擊

[英]How Do I Make A Div Clickable In Wordpress When Running Loop Query

我想在 Wordpress 中使用循環使整個 div 可點擊

我嘗試使用 the_permalink() 在 div 周圍包裹一個錨鏈接;

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

    <div class="content-pop-children">

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>


        <?php

        if ( has_post_thumbnail() ) :
            the_post_thumbnail();
        endif;
        ?>
        <header class="entry-hpop">
            <h1 class="entry-title"><?php the_title(); ?></h1>
        </header>

    <div class="cat-head">
    <!-- Output Category and Link to Cat --> 
    <a href=”<?php echo $category_link ?>”

    title=”<?php echo $category_name ?>”  >

    <?php echo $category_name ?>

    </a>
    </div>  <!-- cat-head --> 
     <!-- the custom excerpt --> 

               <?php echo $newsExerp; ?>


    </article>




       </div>  <!-- content-pop-children --> 

       </a>

我遇到的問題是摘錄不可點擊,而 div 的其余部分沒有正確響應。

這是結果https://gyazo.com/eeace52c1803a3c8a5d004435cb704a1

摘錄區域不可點擊,而其他 div 沒有正確響應,您的幫助將不勝感激

編輯

我應該補充一點,我正在創建一個自定義摘錄,我可以在其中修剪帖子字符的長度,它是如何進行的:

if ( $arr_posts->have_posts() ) :

    while ( $arr_posts->have_posts() ) :
        $arr_posts->the_post();
                        // the custom excerpt
                       $exerp = get_the_excerpt();
                      $newsExerp = strip_tags($exerp);
                      if (strlen($newsExerp) > 500) {
                       // truncate string
                      $stringCut = substr($newsExerp, 0, 500);
                        // make sure it ends in a complete word
                             $newsExerp = substr($stringCut, 0, strrpos($stringCut, ' ')).'...'; 
                                  } 

然后我用<?php echo $newsExerp; ?>調用摘錄<?php echo $newsExerp; ?> <?php echo $newsExerp; ?> ,我是不是遺漏了什么?

嘗試在文章元素中添加錨標記。

<div class="content-pop-children">
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <a href="<?php the_permalink(); ?>">

        <?php

        if ( has_post_thumbnail() ) :
            the_post_thumbnail();
        endif;
        ?>
        <header class="entry-hpop">
            <h1 class="entry-title"><?php the_title(); ?></h1>
        </header>
        <div class="cat-head">
                <?php echo $category_name ?>
        </div>  
        <!-- cat-head --> 
        <!-- the custom excerpt --> 
        <?php echo $newsExerp; ?>
        </a>
    </article>
</div>  <!-- content-pop-children --> 

嘗試發布 'content-pop-children' 的 DOM 內容,很可能您錯誤地形成了 DOM。 嘗試這個

<div class="content-pop-children">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <a href="<?php the_permalink(); ?>">

    <?php

    if ( has_post_thumbnail() ) :
        the_post_thumbnail();
    endif;
    ?>
    <header class="entry-hpop">
        <h1 class="entry-title"><?php the_title(); ?></h1>
    </header>
    <div class="cat-head">
            <?php echo $category_name ?>
    </div>  
    <!-- cat-head --> 
    <!-- the custom excerpt wrapped in a class -->
    <div class='cat-excerpt'> 
    <?php echo $newsExerp; ?>
     </div>
    </a>
</article>
 </div>  <!-- content-pop-children -->`

 .content-pop-children { flex: 1 0 30%; margin: 10px; border-right: 5px solid #000; } .content-pop-children a{ text-decoration:none; }
 <div class="content-pop-children"> <article id="postID"> <a href="https://stackoverflow.com/questions/56928919/how-do-i-make-a-div-clickable-in-wordpress-when-running-loop-query"> <img src="https://placehold.it/300x200"> <header class="entry-hpop"> <h1 class="entry-title">Foo Bar</h1> </header> <div class="cat-head"> FOO TITLE </div> <!-- cat-head --> <!-- the custom excerpt --> <div class="cat-excerpt"> except placed here </div> </a> </article>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM