簡體   English   中英

get_the_title() 顯示帖子或產品標題而不是頁面標題

[英]get_the_title() displays post or product title instead of page title

我在標題中顯示標題時遇到問題。 當我使用 get_queried_object_id() 之類的函數時,會發生同樣的事情,但我無法發現問題出在哪里。 這是我嘗試顯示標題的代碼。

<?php
$page_id = get_queried_object_id();
  ?>

  <div id="logo_section" class="row w-100 h-25  container-fluid justify-content-end p-0 mx-0">
    
  <?php 
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $page_id ), 'single-post-thumbnail' ); 
?>
<div class="jumbotron text-center section w-100 my-auto mr-0  " style="background-size:100% auto; background-repeat: no-repeat;  background-position:center right; background-image: url('<?php echo $image[0]; ?>')">

          <h1 class="display-1 mt-5"><?php echo get_the_title($page_id)  ?></h1>
  </div>
</div>

嘗試在標題中使用 the_title() 函數,它應該適合您。 因為 get_the_title 只在循環內工作,而 the_title() 也在循環外工作。

暫無
暫無

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

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