如何在Wordpress中删除窗口小部件区域

时间:2019-01-20 20:37:02

标签: wordpress custom-wordpress-pages

我正在使用WordPress为房地产代理创建网站。  我想要一个最小的主页,带有文本区域和背景图像。在我正在使用的主题(Agent Press)中,每个页面都有2个我要删除的小部件区域。有办法吗?我不介意使用任何插件或修改代码。谢谢您的时间和考虑。

编辑:这是我的名为sidesis的“父亲”主题中的sidebar.php,我应该在哪里输入您建议的代码? (我不知道编辑该文件是否正确)

<?php
/**
* Genesis Framework.
*
* WARNING: This file is part of the core Genesis Framework. DO NOT edit this 
file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * @package Genesis\Templates
 * @author  StudioPress
 * @license GPL-2.0+
 * @link    http://my.studiopress.com/themes/genesis/
 */

//* Output primary sidebar structure
genesis_markup( array(
'html5'   => '<aside %s>' . genesis_sidebar_title( 'sidebar' ),
'xhtml'   => '<div id="sidebar" class="sidebar widget-area">',
'context' => 'sidebar-primary',
) );

do_action( 'genesis_before_sidebar_widget_area' );
do_action( 'genesis_sidebar' );
do_action( 'genesis_after_sidebar_widget_area' );

genesis_markup( array(
    'html5' => '</aside>', //* end .sidebar-primary
    'xhtml' => '</div>', //* end #sidebar
) );

编辑:这是您想了解的页面的屏幕截图,请告诉我您想了解的更多信息。

enter image description here

编辑:front-page.php

<?php
/**
* This file adds the Home Page to the AgentPress Pro Theme.
*
* @author StudioPress 
* @package AgentPress Pro
* @subpackage Customizations
*/

//* Enqueue scripts
add_action( 'wp_enqueue_scripts', 'agentpress_front_page_enqueue_scripts' 
 );
 function agentpress_front_page_enqueue_scripts() {

//* Load scripts only if custom background is being used
if ( ! get_option( 'agentpress-home-image' ) )
    return;

//* Enqueue Backstretch scripts
wp_enqueue_script( 'agentpress-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'agentpress-backstretch-set', get_bloginfo( 'stylesheet_directory' ).'/js/backstretch-set.js' , array( 'jquery', 'agentpress-backstretch' ), '1.0.0' );

wp_localize_script( 'agentpress-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', get_option( 'agentpress-home-image' ) ) ) );

//* Add agentpress-pro-home body class
add_filter( 'body_class', 'agentpress_body_class' );

}

add_action( 'genesis_meta', 'agentpress_home_genesis_meta' );
/**
* Add widget support for homepage. If no widgets active, display the default loop.

*  * /     函数agentpress_home_genesis_meta(){

if ( is_active_sidebar( 'home-featured' ) || is_active_sidebar( 'home-top' ) || is_active_sidebar( 'home-middle-1' ) || is_active_sidebar( 'home-middle-2' ) || is_active_sidebar( 'home-middle-3' ) || is_active_sidebar( 'home-bottom' ) ) {

    //* Force full-width-content layout setting
    add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

    //* Remove breadcrumbs
    remove_action( 'genesis_before_content_sidebar_wrap', 'genesis_do_breadcrumbs' );

    //* Remove the default Genesis loop
    remove_action( 'genesis_loop', 'genesis_do_loop' );

    //* Add home featured area
    add_action( 'genesis_after_header', 'agentpress_home_featured_widget' );

    //* Add home widget area
    add_action( 'genesis_before_footer', 'agentpress_home_widgets', 1 );

}

}

 function agentpress_body_class( $classes ) {

    $classes[] = 'agentpress-pro-home';
    return $classes;

}

function agentpress_home_featured_widget() {

genesis_widget_area( 'home-featured', array(
    'before' => '<div class="home-featured full-width widget-area"><div class="wrap">',
    'after' => '</div></div>',
) );

}

function agentpress_home_widgets() {

/*genesis_widget_area( 'home-top', array(
    'before' => '<div class="home-top full-width widget-area"><div class="wrap">',
    'after'  => '</div></div>',
) ); */



if ( is_active_sidebar( 'home-middle-1' ) || is_active_sidebar( 'home-middle-2' ) || is_active_sidebar( 'home-middle-3' ) ) {

    echo '<div class="home-middle"><div class="wrap">';

        genesis_widget_area( 'home-middle-1', array(
            'before' => '<div class="home-middle-1 full-width widget-area">',
            'after'  => '</div>',
        ) );

        genesis_widget_area( 'home-middle-2', array(
            'before' => '<div class="home-middle-2 widget-area">',
            'after'  => '</div>',
        ) );

        genesis_widget_area( 'home-middle-3', array(
            'before' => '<div class="home-middle-3 widget-area">',
            'after'  => '</div>',
        ) );

    echo '</div></div>';

}

genesis_widget_area( 'home-bottom', array(
    'before' => '<div class="home-bottom full-width widget-area"><div class="wrap">',
    'after'  => '</div></div>',
) );

}

genesis();`

2 个答案:

答案 0 :(得分:1)

您需要在侧边栏代码上设置if语句。使用wordpress的is_page()功能:

if( ! is_page('home') ){  // Remove the sidebar on home page

   dynamic_sidebar('your-sidebar-id');

}

您还可以通过ID或Slug在特定页面上设置侧边栏。

if( is_page( 123 ) ){  // via ID

   dynamic_sidebar('your-sidebar-id-1');  // Sidebar 1

}elseif( is_page('contact-us') ){  // via slug

   dynamic_sidebar('your-sidebar-id-2');  // Sidebar 2

}

答案 1 :(得分:0)

编辑:

  1. 导航至外观> WordPress中左侧的编辑器 仪表板。
  2. 在“编辑主题”页面上,选择右侧的sidbar.php页面 模板部分。
  3. sidebar.php的代码将在主题编辑器窗口中加载。
  4. 在代码中添加注释,如右侧快照中所示。的HTML 注释如下:
<!-- Begin Comment

Code goes in between here

End Comment -->

在主题编辑器的页面中添加注释代码,然后单击“更新文件”