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

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

WordPress - 在循環中第一次發布后插入內容

WordPress - 在循環中第一次發布后插入內容

PHP
鴻蒙傳說 2022-07-22 16:31:34
我已經設置 PHP 代碼在顯示帖子的 WordPress 主頁上的第一個帖子之后插入類別列表。它工作正常。我的問題是,我想在列表上方顯示一個標題,可能是帶有文本“瀏覽我們的類別”或其他內容的 HTML H3 標記。我的問題是,我在哪里放置這個 HTML 標題?如果我把它放在div 標簽中(見下面的代碼),標題會在頁面下方重復,在所有其他帖子下方。我只希望它出現一次 - 在第一篇文章之后,就在我的類別列表上方。我嘗試將其作為 $output 變量的一部分,例如: $output = '<h3>Browse Categories</h3>'; $output .= '<a class="cat-links" href=" ... etc.但這不起作用。我正在使用的代碼如下:<?php if (have_posts()) : while (have_posts()) : the_post(); ?><?php get_template_part('content', get_theme_mod('solopine_home_layout')); ?><?php // CUSTOM CODE TO DISPLAY LIST OF CATEGORIES ?><div style="text-align:center; padding-bottom:100px;"><?php if( $wp_query->current_post == 0 ) {     $allowed = array(17,18,19,20);    $categories = get_categories(array(        'orderby' => 'name',        'parent'  => 0,        'hide_empty'=> true,        'include' => $allowed,        )        );    $separator = ' ';    $output = '';    if($categories){    foreach($categories as $category) {    $output .= '<a class="cat-links" href="'.get_category_link( $category ).'" title="' .            esc_attr( sprintf( __( "View all posts in %s" ),            $category->name ) ) . '">'.$category-     >cat_name.'</a>';        }        echo trim($output);    }} ?>      </div><?php // END CUSTOM CODE ?> <?php endwhile; ?>希望有人可以提供幫助。
查看完整描述

1 回答

?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

在 foreach 循環之前使用它。echo '<h3>Browse Categories</h3>';



查看完整回答
反對 回復 2022-07-22
  • 1 回答
  • 0 關注
  • 140 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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