1. Home
  2. Docs
  3. Developer Guide
  4. Miscellaneous and Snippet...
  5. Adding a sidebar to single property page

Adding a sidebar to single property page

Assuming you're using your own theme, there's no simple way for us to simply activate a sidebar on the single property page. Every theme has different classes/CSS for styling the sidebar structure, and each a different way of managing these.

The best solution to getting a sidebar onto the property details page would be to override the single-property.php template. More about overriding templates can be found here.

Once copied into your own theme you can edit it accordingly to include a sidebar. An example of this might be as follows:

<?php
/**
 * The Template for displaying a single property.
 *
 * Override this template by copying it to yourtheme/propertyhive/single-property.php
 *
 * @author      PropertyHive
 * @package     PropertyHive/Templates
 * @version     1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

get_header( 'propertyhive' ); ?>

    <?php
        /**
         * propertyhive_before_main_content hook
         *
         * @hooked propertyhive_output_content_wrapper - 10 (outputs opening divs for the content)
         */
        do_action( 'propertyhive_before_main_content' );
    ?>

    <?php while ( have_posts() ) : the_post(); ?>

        <?php ph_get_template_part( 'content', 'single-property' ); ?>

    <?php endwhile; // end of the loop. ?>

    <div class="sidebar">
        <?php dynamic_sidebar( 'sidebar-name' ); ?>
    </div>
    
    <?php
        /**
         * propertyhive_after_main_content hook
         *
         * @hooked propertyhive_output_content_wrapper_end - 10 (outputs closing divs for the content)
         */
        do_action( 'propertyhive_after_main_content' );
    ?>

<?php get_footer( 'propertyhive' ); ?>

Note that this is the default template with the addition of the 3 lines relating to the sidebar. It would then be case of styling the sidebar to place it left/right and the width accordingly.

Was this article helpful to you? No Yes

How can we help?