Hooks for shortcodes

Viewing 15 posts - 1 through 15 (of 19 total)

These forums are closed to new replies / tickets. Please open a support ticket from our new Support page.

  • Author
    Posts
  • #2024
    Trimson Partners
    Participant

    Hi Merv,

    Love the plugin. I’m a front-end developer, and I’m creating a custom theme. Just hoping if you could help me out with a few things.

    I followed your instructions on how to implement the single listing hook, but it still appears not to be overriding the template. My code is as follows:

    if (class_exists(‘Easy_Property_Listings’)) {
    function epl_my_custom_single_listing_template( ) {
    $epl_settings = epl_settings();
     
    $d_gallery = ”;
    if(!empty($epl_settings) && isset($epl_settings['display_single_gallery'])) {
    $d_gallery  = $epl_settings['display_single_gallery'];
    }
     
    $d_gallery_n = ”;
    if(!empty($epl_settings) && isset($epl_settings['display_gallery_n'])) {
    $d_gallery_n    = $epl_settings['display_gallery_n'];
    }
     
    $d_map_position = ”;
    if(!empty($epl_settings) && isset($epl_settings['epl_display_single_map_position'])) {
    $d_map_position = $epl_settings['epl_display_single_map_position'];
    }
     
    $d_feature_col = ”;
    if(!empty($epl_settings) && isset($epl_settings['display_feature_columns'])) {
    $d_feature_col  = $epl_settings['display_feature_columns'];
    }
     
    include( EPL_PATH_TEMPLATES_CONTENT . ‘listing-meta.php’ );
    include( MY_TEMPLATE_PATH . ‘properties-single.php’ );
    }
    add_action(‘epl_single_template’, ‘epl_my_custom_single_listing_template’);
    }

    My file is ‘properties-single.php’ and lives in my template folder. Anything I’m doing wrong?

    The other thing is that I am only using shortcodes to display listings, and as such, I’d like to override the ‘loop-listing-blog-default.php’ file in order to move some elements around, etc. Is there a hook I can use to edit that safely too?

    Look forward to hearing from you,

    Thanks,
    Grace

    #2025
    Merv Barrett
    Keymaster

    Are you running the latest version of Easy Property Listings 1.2 from WordPress.org? Perhaps you have an older development version from GitHub.

    I’ve just run a test and the above code works. The issue was in previous versions of the plugin which did not accept the hook.

    Archive Template is the same process using the hook epl_loop_template

    add_action ( ‘epl_loop_template’ , ‘epl_my_custom_archive_template’ );

    be sure to include the listing-meta as you did in the above example
    include( EPL_PATH_TEMPLATES_CONTENT . ‘listing-meta.php’ );

    so the final code should be like this

    if (class_exists('Easy_Property_Listings')) {
    function epl_my_custom_archive_template( ) {
    $epl_settings = epl_settings();
    
     
    include( EPL_PATH_TEMPLATES_CONTENT . ‘listing-meta.php’ );
    include( MY_TEMPLATE_PATH . ‘property-archive-single.php’ );
    }
    add_action(‘epl_loop_template’, ‘epl_my_custom_archive_template’);
    }

    If you are running the latest 1.2 version, can you supply your FTP and WordPress login details here. Press the Set as Private reply below.

    • This reply was modified 9 years, 6 months ago by Merv Barrett.
    #2027
    Merv Barrett
    Keymaster

    Also regarding the shortcode. Once you add the archive hook as above it should automatically use the new template with the shortcodes.

    #2028
    Merv Barrett
    Keymaster
    This reply has been marked as private.
    #2036
    Trimson Partners
    Participant
    This reply has been marked as private.
    #2055
    Trimson Partners
    Participant
    This reply has been marked as private.
    #2056
    Trimson Partners
    Participant
    This reply has been marked as private.
    #2057
    Merv Barrett
    Keymaster

    I think the issue with your function is the apostrophe. When copying and pasting from here the apostrophe is not correct its on an angle which is a special character, it should just be a ‘

    #2058
    Merv Barrett
    Keymaster

    another issue is the MY_TEMPLATE_PATH which you have not defined. That should be a path to the child theme. In this case becasue your function is in the same folder its not needed.

    I’ve made the changes and your templates are now displaying.

    I’ll get back to you regarding the search widget changes.
    — For now just keep a copy of that file and i’ll work out a solution for this.

    RE:
    I’m using the regular WP loop on the home page to return the properties, so that I have more control over placement of items etc (because it will be quite different to the pages I am using the shortcode to display listings). Just wondering how I can access some of the meta values using the regular loop? Such as ‘featured => yes’, and also to spit out each bit of info re: bedrooms, bathrooms, etc.

    —- No need to include the listing-meta.php in the shortcode as it is already loading the meta like beds, baths, price based on the home page example.

    — Just add a custom action to your function function in your main loop.
    eg in your index.php create an action like do_action( ‘my_custom_home_loop’ , ‘epl_my_custom_single_listing_template’ );

    — Then you could create several separate custom templates as you did already and insert them where needed.

    — The featured listing is an issue becasue of how the importer works. In order to mark a listing as featured manually without importing listings is no problem. The problem is that in order to import a featured listing from the XML feed then that will be a featured property on Realestate.com.au.

    Great looking site

    #2071
    Trimson Partners
    Participant

    Thanks so much Merv!

    I can’t believe I completely overlooked the special character apostrophe. Very silly of me. Thanks for the tip re: MY_TEMPLATE_PATH. Hook overrides working really well now.

    Re: the home page loop, yep, I extracted the meta data I needed from listing_meta.php, in order to not have to action the entire listing_meta.php. I’ll only be using that style of property display on the home page, so I probably won’t create an action for a new template. But thanks for the tip – I am new to WP actions/hooks, as you can probably tell.

    Re: the featured listing. I’m ok with adding the ‘featured’ part manually once data is in the WP site, that’s no trouble at all. But I’m just wondering how to target that meta data in my loop.

    So my loop at the moment is just:

    <?php $args = array(
    'post_type' => 'property',
    );
    $query = new WP_Query( $args );

    I’m wondering if there’s a way of targeting the meta field of ‘property_featured’ using meta_key? I.e:

    <?php $args = array(
    'post_type' => 'property',
    'meta_key' => 'property_featured',
    'meta_query' => array(
    		array(
    			'key'     => 'property_featured',
    			'value'   =>  true,
    			'compare' => 'IN',
    		),
    	),
    );
    $query = new WP_Query( $args );

    Something like that?

    Cheers,
    Grace

    #2087
    Trimson Partners
    Participant

    Just an update,

    The above code actually worked fine, all I needed to do was change ‘true’ to ‘yes’.

    So, to create a simple loop that displays the featured properties only, the WP_Query is:

    <?php $args = array(
    'post_type' => 'property',
    'meta_key' => 'property_featured',
    'meta_query' => array(
    		array(
    			'key'     => 'property_featured',
    			'value'   =>  'yes',
    			'compare' => 'IN',
    		),
    	),
    );
    $query = new WP_Query( $args ); ?>

    Good to know for future use if I needed to filter based on any of the other meta values too!

    Cheers,
    Grace

    #3427
    Trimson Partners
    Participant

    Hi Merv,

    I have another question about template overrides. I’m trying to figure out how to add custom pagination to the properties loop. I’m assuming I’d make my edits in archive_listing.php. I have a copy of that in my template folder, but it doesn’t seem to do anything when I try to make changes. This makes me wonder whether I’ve even set that up correctly. Was I meant to create a hook for that file too? For some reason I just have it placed in the template folder and that’s it.

    But, even when I try to make edits to the archive_listing.php file in the plugin folder (lib/templates/themes/default) it doesn’t seem to display them either.

    A little bit lost.

    Any chance you could point me in the right direction?

    Thanks,
    Grace

    #3461
    Merv Barrett
    Keymaster

    Looking at your filename if that is how it in on your site and what is possibly the issue is to use a hyphen – not an underscore. Try that

    archive_listing.php should be archive-listing.php

    #3465
    Trimson Partners
    Participant

    Oops, sorry, I mistyped it. My file is archive-listing.php, with a hyphen. So it is meant to work when it just sits in the root of my template folder?

    #3468
    Merv Barrett
    Keymaster

    Correct, that should be the case. Add some characters to the file and refresh. Usually i’ll pop […] in the file and save.

These forums are closed to new replies / tickets. Please open a support ticket from our new Support page.

Viewing 15 posts - 1 through 15 (of 19 total)
  • The forum ‘Priority Support’ is closed to new topics and replies.