以下 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 回答
- 0 關注
- 157 瀏覽
添加回答
舉報
0/150
提交
取消