• Resolved xhide00

    (@xhide00)


    Hi,
    I’m Struggling to find out to see if this is possible.

    basically on the Archive-listing page it displays list of entries with “Beds, Baths, Sq Ft” but i have other categories that are not requiring these information.

    Conditionally I need to display “Cap Rate, Lot SF, Net Income” for Commercial and Business category listings.

    (by the way I’ve added these “cap rate, net income, etc.” in the class-listings.php)

    please let me know if there is a way to display these conditionally or have multiple archive-listing.php pages to display these.

    Thank you!

    https://www.ads-software.com/plugins/wp-listings/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author agentevolution

    (@agentevolution)

    Yes, if you have a specific taxonomy and/or term that doesn’t require that info or you want to display that info on, you can use the archive-listing.php as a template, copy it to your theme folder, and rename it according to the Template Hierarchy. i.e. taxonomy-taxonomynametaxonomyterm.php and then customize it to your needs.

    Also, instead of editing class-listings.php to add property details, you should be using a filter added to your theme’s functions.php. A write up on how to do this is available here: https://www.agentevolution.com/how-to-2/change-wp-listings-property-details/

    Thread Starter xhide00

    (@xhide00)

    Hi, thank you for your reply.

    changing the file name per template hierarchy didn’t work for me.
    i’ve copied and paste to change the archive-listing.php file to
    taxonomy-property-types-commercial.php in the theme folder, but didn’t do anything.

    instead it now grabs the archive-listing.php from the plug-in folder.

    please let me know if there is something else i have to do to make this link work.

    thank you so much!

    Thread Starter xhide00

    (@xhide00)

    Hm… i Tried changing the archive-listing.php to followings names, but all are not working…

    taxonomy-property-types-commercial.php
    taxonomy-listings-property-types-commercial.php
    listings-property-types-commercial.php
    archive-property-types-commercial.php
    archive-listing-property-types-commercial.php

    please help.

    perhaps there is a file in the plugin folder is somehow controlling it to not use WP’s taxonomy rule?

    Plugin Author agentevolution

    (@agentevolution)

    Yes, there is. In the plugin /includes/functions.php there is a template_redirect filter.

    It’s not recommended to edit the plugin files, so instead you should remove that filter in your theme’s functions.php file and add a new filter… like so:

    // Remove WP Listings filter
    remove_filter( 'template_include', 'wp_listings_template_include' );
    
    // Add custom filter that removes the redirect for taxonomy pages
    add_filter( 'template_include', 'custom_wp_listings_template_include' );
    function custom_wp_listings_template_include( $template ) {
    
    	$post_type = 'listing';
    
    	if ( is_post_type_archive( $post_type ) ) {
    		if ( file_exists(get_stylesheet_directory() . '/archive-' . $post_type . '.php') ) {
    			$template = get_stylesheet_directory() . '/archive-' . $post_type . '.php';
    			return $template;
    		} else {
    			return dirname( __FILE__ ) . '/views/archive-' . $post_type . '.php';
    		}
    	}
    
    	if ( is_single() && $post_type == get_post_type() ) {
    
    		global $post;
    
    		$custom_template = get_post_meta( $post->ID, '_wp_post_template', true );
    
    		/** Prevent directory traversal */
    		$custom_template = str_replace( '..', '', $custom_template );
    
    		if( ! $custom_template )
    			if( file_exists(get_stylesheet_directory() . '/single-' . $post_type . '.php') )
    				return $template;
    			else
    				return dirname( __FILE__ ) . '/views/single-' . $post_type . '.php';
    		else
    			if( file_exists( get_stylesheet_directory() . "/{$custom_template}" ) )
    				$template = get_stylesheet_directory() . "/{$custom_template}";
    			elseif( file_exists( get_template_directory() . "/{$custom_template}" ) )
    				$template = get_template_directory() . "/{$custom_template}";
    
    	}
    
    	return $template;
    }
    Thread Starter xhide00

    (@xhide00)

    Hi, Thanks for that info.
    I copied that entire code into my theme’s functions.php, but it did not change anything. However, because your info about having a filter led me to visit plugin’s functions.php file.

    There I physically deleted out where the “add_filter( ‘template_include’…” code resides.

    and suddenly everything worked.

    I know you suggested not to touch plugin’s file and add above code to theme’s functions.php, but at the moment this seems like the only solution.

    I’ve also tried adding:

    // Remove WP Listings filter
    remove_filter( 'template_include', 'wp_listings_template_include' );

    to a line after the plugin’s functions.php file and it worked also. it’s just when I paste this code into Theme’s functions.php, it doesn’t work.

    perhaps the reason is that plugin’s functions.php file code loads after theme’s functions.php?

    please let me know.

    thank you!

    Plugin Author agentevolution

    (@agentevolution)

    OK. Yes that’s true. You’ll need to put that code into it’s own function and hook it into the plugins_loaded action hook:

    add_action( 'plugins_loaded', 'wp_listings_override' );
    function wp_listings_override() {
    // Add previously posted filters code here
    }
    Thread Starter xhide00

    (@xhide00)

    This still doesn’t work.
    plugin’s functions.php file still loads after the theme’s functions.php.
    so it overrides the override.

    It seems like modifying the plugin’s functions.php file is the only way…

    Plugin Author agentevolution

    (@agentevolution)

    Try using the after_setup_theme hook instead of plugins_loaded.

    Thread Starter xhide00

    (@xhide00)

    there you go!
    it works now.
    the code I inserted was:

    add_action( 'after_setup_theme', 'wp_listings_override' );
    
    function wp_listings_override() {
    // Remove WP Listings filter
    remove_filter( 'template_include', 'wp_listings_template_include' );

    thank you!

    Plugin Author agentevolution

    (@agentevolution)

    Excellent. We’ll look into making this easier in the future. The way it works now is anything that is a listing taxonomy will use the archive-listing.php file. It could be done better but would require a lot more logic in that template_include filter.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Can I customize to have multiple archive-listing.php ?’ is closed to new replies.