Add custom sidebar for single property

This commit is contained in:
Hoang Huu
2020-02-14 09:38:54 +07:00
parent 50c6d4d421
commit 7a4f3b67dc
7 changed files with 518 additions and 352 deletions

View File

@@ -1068,7 +1068,7 @@ function opalestate_areasize_unit_format( $value = '' ) {
$unit = $measurement_units[ $unit ];
}
return sprintf( _x( '%1$s <span>%2$s</span>', 'areasize info','opalestate-pro' ), $value, $unit );
return sprintf( _x( '%1$s <span>%2$s</span>', 'areasize info', 'opalestate-pro' ), $value, $unit );
}
add_filter( 'opalestate_areasize_unit_format', 'opalestate_areasize_unit_format' );
@@ -1315,17 +1315,37 @@ function opalestate_clean( $var ) {
* with the optional prefix. As such the returned value is not universally unique,
* but it is unique across the life of the PHP process.
*
* @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
* @param string $prefix Prefix for the returned ID.
* @return string Unique ID.
* @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
*
* @staticvar int $id_counter
*
* @param string $prefix Prefix for the returned ID.
* @return string Unique ID.
*/
function opalestate_unique_id( $prefix = '' ) {
static $id_counter = 0;
if ( function_exists( 'wp_unique_id' ) ) {
return wp_unique_id( $prefix );
}
return $prefix . (string) ++$id_counter;
}
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function opalestate_widgets_init() {
register_sidebar( [
'name' => esc_html__( 'Single Property Sidebar', 'opalestate-pro' ),
'id' => 'opalestate-single-property',
'description' => esc_html__( 'Add widgets here to appear in your single property sidebar area.', 'opalestate-pro' ),
'before_widget' => '<div id="%1$s" class="widget opalestate-single-property-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h5 class="widget-title">',
'after_title' => '</h5>',
] );
}
add_action( 'widgets_init', 'opalestate_widgets_init' );

View File

@@ -330,3 +330,16 @@ function opalestate_load_plugin_template( $template ) {
add_filter( 'template_include', 'opalestate_load_plugin_template' );
add_action( 'opalestate_before_property_loop_item', 'opalestate_property_featured_label' );
add_action( 'opalestate_before_property_loop_item', 'opalestate_property_label' );
/**
* Add custom sidebar widgets to single property sidebar.
*/
function opalestate_single_property_sidebar_widgets() {
if ( is_active_sidebar( 'opalestate-single-property' ) ) : ?>
<div class="opalestate-single-property-widgets">
<?php dynamic_sidebar( 'opalestate-single-property' ); ?>
</div>
<?php endif;
}
add_action( 'opalestate_single_property_sidebar', 'opalestate_single_property_sidebar_widgets', 99 );