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

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

WordPress 自定義演示側邊欄未出現在帖子中

WordPress 自定義演示側邊欄未出現在帖子中

PHP
偶然的你 2023-08-19 10:25:57
以下 php 文件獲取一個自定義演示側邊欄,顯示在管理小部件菜單中,但不顯示在實際帖子上(文件位于同名文件夾中,該文件夾位于 WP 文件目錄中的插件文件夾中) - 將文本小部件添加到自定義要測試的側邊欄:<?php/*** Plugin Name:    Single Post CTA* Plugin URI:     https://github.com/cdils/single-post-cta* Description:    Adds sidebar (widget area) to single posts* Version:        0.1* Author:         Carrie Dils* Author URI:     https://carriedils.com* License:        GPL v2+* License URI:    https://www.gnu.org/licenses/gpl-2.0.html* Text Domain:    spc*/// If this file is called directly, abortif ( !defined( 'ABSPATH' ) ) {  die;}/*** Load stylesheet*/function spc_load_stylesheet() {  if ( is_single() ) {    wp_enqueue_style( 'spc_stylesheet', plugin_dir_url(__FILE__) .'spc-styles.css' );  }}// Hook stylesheetadd_action( 'wp_enqueue_scripts', 'spc_load_stylesheet' );// Register a custom sidebarfunction spc_register_sidebar() {      register_sidebar( array(        'name'          => __( 'Single Post CTA', 'spc' ),        'id'            => 'spcsidebar',        'description'   => __( 'Displays widget area on single posts', 'spc' ),        'before_widget' => '<div class="widget spc">',        'after_widget'  => '</div>',        'before_title'  => '<h2 class="widgettitle spc-title">',        'after_title'   => '</h2>',   ) );}// Hook sidebaradd_action( 'widgets_init', 'spc_register_sidebar' );// Display sidebar on single postsfunction spc_display_sidebar( $content ) {    if ( is_single() ) {      dynamic_sidebar( 'spcsidebar' );    }    return $content;}// Add dynamic sidebaradd_filter( 'the content', 'spc_display_sidebar' );以下是與自定義側邊欄文件位于同一文件夾中的關聯樣式表:.spc {    background: gray;    color: blue;}定制器下的小部件菜單顯示“您的主題有 1 個其他小部件區域,但此特定頁面不顯示它”。這個 WordPress 指南https://developer.wordpress.org/themes/functionity/sidebars/似乎表明必須在主題或子主題的functions.php 文件中注冊側邊欄/小部件,然后創建一個側邊欄-{name}在其中運行dynamic_sidebar 函數的.php 文件。是這樣嗎?我正在使用 Genesis Sample 子主題,并切換到 2020 年和 2017 年 WordPress 主題,或停用所有其他插件都沒有解決問題。
查看完整描述

2 回答

?
瀟瀟雨雨

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

過濾器應該是add_filter( 'the_content', 'spc_display_sidebar' );. 你忘了下劃線。

如果您嘗試在頁面帖子類型中顯示側邊欄,那么這is_single()是行不通的。嘗試is_singular()一下。



查看完整回答
反對 回復 2023-08-19
?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

Mistack 位于鉤子中,而不是“內容”,請使用“the_content”

前任。add_filter( 'the_content', 'spc_display_sidebar' );


查看完整回答
反對 回復 2023-08-19
  • 2 回答
  • 0 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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