• Добрый день! Помогите, пожалуйста, разобраться в файле sidebar.php. Тема Contango.
    Дело в том, что данная тема не имеет боковую панель с идентификатором «sidebar-1». Вследствие чего в мобильной теме сайта не отображается боковая панель.

    Вот код sidebar.php

    <?php
    /** Register widget areas. */
    add_action( 'widgets_init', 'contango_register_sidebars' );
    
    /** Registers the the core sidebars */
    function contango_register_sidebars() {
    
    	/* Get the available core framework sidebars. */
    	$sidebars = contango_sidebars();
    	
    	/* Loop through the supported sidebars. */
    	foreach ( $sidebars as $key => $val ) {
    		
    
    		/* Set up some default sidebar arguments. */
    		$defaults = array(
    		  'before_widget'	=> '<aside id="%1$s" class="widget %2$s widget-%2$s clearfix"><div class="widget-wrap widget-inside">',
    		  'after_widget'	=> '</div></aside>',
    		  'before_title'	=> '<h3 class="widget-title">',
    		  'after_title'	=> '</h3>'
    		);
    		
    		/* Parse the sidebar arguments and defaults. */
    		$args = wp_parse_args( $sidebars[$key], $defaults );
    		
    		/* Register the sidebar. */
    		register_sidebar( $args );
    		
    	}
    
    }
    
    /** Returns an array of the core framework's available sidebars for use in theme */
    function contango_sidebars() {
    
    	/* Set up an array of sidebars. */
    	$sidebars = array(
    		
    		'contango-primary-sidebar' => array(
    			'name' => __( 'Contango Primary Sidebar', 'contango' ),
    			'id' => 'contango-primary-sidebar',
    			'description' => __( 'The main (primary) widget area, most often used as a sidebar.', 'contango' )
    		)
    	);
    
    	/* Return the sidebars. */
    	return $sidebars;
    }

    Что бы присвоить сайббару идентификатор 1, по инструкции взятой от сюда: http://yrokiwp.ru/cms-wordpress/plagin/adaptatsii-sayta-pod-mobilnyie-ustroystva/ , я меняю

    'id' => 'contango-primary-sidebar',

    на

    'id' => 'sidebar-1',

    В итоге получается, что в боковой колонке на сайте пропадают те виджеты, которые я устанавливал, а появляются стандартные прописанные по умолчанию в этой теме и боковая колонка в консоли не редактируется.

    Подскажите, что я делаю не так? Буду очень благодарен.

Просмотр 4 ответов — с 1 по 4 (всего 4)
  • Для начала необходимо зарегистрировать новый сайдбар в functions.php после чего создать файл в сайдбаром и наполнить его необходимым. В нужном месте — вывести.

    Дело в том, что тот что есть сайдбар не зарегистрирован в functions.php

    Вот код

    <?php
    /** Load the Core Files */
    require_once( trailingslashit( get_template_directory() ) . 'lib/init.php' );
    new Contango();
    
    /** Do theme setup on the 'after_setup_theme' hook. */
    add_action( 'after_setup_theme', 'contango_theme_setup' );
    
    /** Theme setup function. */
    function contango_theme_setup() {
    
    	/** Add theme support for Feed Links. */
    	add_theme_support( 'automatic-feed-links' );
    
    	/*
    	 * Let WordPress manage the document title.
    	 * By adding theme support, we declare that this theme does not use a
    	 * hard-coded <title> tag in the document head, and expect WordPress to
    	 * provide it for us.
    	 */
    	add_theme_support( 'title-tag' );
    
    	/** Post Formats */
    	add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'video' ) );
    
    	/** Add theme support for Custom Background. */
    	add_theme_support( 'custom-background', array( 'default-color' => 'e9e9e9', 'default-image' => '%s/images/bg-pattern.png', 'wp-head-callback' => 'contango_custom_background_callback' ) );
    
    	/** Set content width. */
    	contango_set_content_width( 580 );
    
    	/** Add custom image sizes. */
    	add_action( 'init', 'contango_add_image_sizes' );
    
    }
    
    /** Adds custom image sizes */
    function contango_add_image_sizes() {
    	add_image_size( 'featured', 200, 180, true );
    }
    
    /**
     * This is a fix for when a user sets a custom background color with no custom background image.  What
     * happens is the theme's background image hides the user-selected background color.  If a user selects a
     * background image, we'll just use the WordPress custom background callback.
     *
     * @link http://core.trac.wordpress.org/ticket/16919
     */
    function contango_custom_background_callback() {
    
    	/* Get the background image. */
    	$image = get_background_image();
    
    	/* If there's an image, just call the normal WordPress callback. We won't do anything here. */
    	if ( !empty( $image ) ) {
    		_custom_background_cb();
    		return;
    	}
    
    	/* Get the background color. */
    	$color = get_background_color();
    
    	/* If no background color, return. */
    	if ( empty( $color ) ) {
    		return;
    	}
    
    	/* Use 'background' instead of 'background-color'. */
    	$style = "background: #{$color};";
    
    ?>
    <style type="text/css">body.custom-background { <?php echo trim( $style ); ?> }</style>
    <?php
    }

    Выходит так, что functions.php не отвечает за сайдбарды.

    Вы не правы. Посмотрите, что инклюдит файл — init.php, я более, чем уверен, что внутри еще несколько инклюдов, и где-то среди них и регистрируется сайдбар ваш.

    https://codex.wordpress.org/Function_Reference/register_sidebar — вот разбор этого момента на кодексе.

    Вот файл init.php

    <?php
    /** Core Theme Framework */
    class Contango {
    	
    	/** Constructor Method */
    	function __construct() {
    
    		/** Define a Global variable Standard Class */
    		global $contango;
    		$contango = new stdClass;
    		
    		/** Define framework, parent theme, and child theme constants. */
    		add_action( 'after_setup_theme', array( &$this, 'constants' ), 1 );
    		
    		/** Load the core functions required by the rest of the framework. */
    		add_action( 'after_setup_theme', array( &$this, 'core' ), 2 );
    		
    		/** Language functions and translations setup. */
    		add_action( 'after_setup_theme', array( &$this, 'i18n' ), 3 );
    		
    		/** Load the framework functions. */
    		add_action( 'after_setup_theme', array( &$this, 'functions' ), 12 );
    		
    		/** Load admin files. */
    		add_action( 'wp_loaded', array( &$this, 'admin' ) );		
    
    	}
    	
    	/** Define Constant Paths */
    	function constants() {
    
    		/** Directory Location Constants */
    		
    		/** Sets the path to the parent theme directory. */
    		define( 'CONTANGO_DIR', trailingslashit( get_template_directory() ) );
    		define( 'CONTANGO_LIB_DIR', trailingslashit( CONTANGO_DIR . 'lib' ) );
    		
    		define( 'CONTANGO_FUNCTIONS_DIR', trailingslashit( CONTANGO_LIB_DIR . 'functions' ) );
    		define( 'CONTANGO_ADMIN_DIR', trailingslashit( CONTANGO_LIB_DIR . 'admin' ) );
    		define( 'CONTANGO_JS_DIR', trailingslashit( CONTANGO_LIB_DIR . 'js' ) );
    		define( 'CONTANGO_CSS_DIR', trailingslashit( CONTANGO_LIB_DIR . 'css' ) );
    		
    		/** URI Location Constants */
    		
    		/** Sets the path to the parent theme directory URI. */
    		define( 'CONTANGO_URI', trailingslashit( get_template_directory_uri() ) );
    		define( 'CONTANGO_LIB_URI', trailingslashit( CONTANGO_URI . 'lib' ) );
    		
    		define( 'CONTANGO_ADMIN_URI', trailingslashit( CONTANGO_LIB_URI . 'admin' ) );
    		define( 'CONTANGO_JS_URI', trailingslashit( CONTANGO_LIB_URI . 'js' ) );
    		define( 'CONTANGO_CSS_URI', trailingslashit( CONTANGO_LIB_URI . 'css' ) );
    		
    	}
    	
    	/** Loads the core framework functions. */
    	function core() {
    		
    		/** Load the core framework functions. */
    		require_once( CONTANGO_FUNCTIONS_DIR . 'core.php' );
    	
    	}
    	
    	/** Loads translation files */
    	function i18n() {
    
    		/** Translations can be filed in the /languages/ directory */
    		load_theme_textdomain( 'contango', CONTANGO_DIR . 'languages' );
    		
    	}
    	
    	/** Loads the framework functions. */
    	function functions() {
    
    		/** Load media-related functions. */
    		require_once( CONTANGO_FUNCTIONS_DIR . 'media.php' );
    		
    		/** Load utility functions. */
    		require_once( CONTANGO_FUNCTIONS_DIR . 'utility.php' );
    		
    		/** Load theme settings functions. */
    		require_once( CONTANGO_FUNCTIONS_DIR . 'settings.php' );
    		
    		/** Load menus functions. */
    		require_once( CONTANGO_FUNCTIONS_DIR . 'menus.php' );		
    		
    		/** Load sidebars functions. */
    		require_once( CONTANGO_FUNCTIONS_DIR . 'sidebars.php' );
    		
    		/** Load featured image functions. */
    		require_once( CONTANGO_FUNCTIONS_DIR . 'featured-image.php' );
    		
    		/** Load custom header functions. */
    		require_once( CONTANGO_FUNCTIONS_DIR . 'custom-header.php' );
    		
    	}
    	
    	/** Load admin files for the framework. */
    	function admin() {
    
    		/* Check if in the WordPress admin. */
    		if ( is_admin() ) {
    
    			/* Load the main admin file. */
    			require_once( CONTANGO_ADMIN_DIR . 'admin.php' );
    
    		}
    	}	

    За сайдбар здесь отвечает эта строка:

    require_once( CONTANGO_FUNCTIONS_DIR . 'sidebars.php' );

    Но, что это значит?

    register_sidebar прописан только в sidebar.php. По крайней мере в других файлах я его найти не могу.

Просмотр 4 ответов — с 1 по 4 (всего 4)

Тема «Помогите разобраться в файле sidebar.php» закрыта для новых ответов.