This page shares examples for developers to customize GeoDirectory features. The most commonly used code snippets are located here, and the most common CSS styling changes are here. Developers using any of the examples will need to create their own custom styles to attain final results. For instructions about how to change styles or add snippets, please see Customizing Your Style. For support with these examples, please contact a developer at the GD Experts Directory.

Listing Page – Add the author image to the listing

This Snippet will add the listing author image to each listing shown on the listing page. The image will appear after the listing title. You will need to create your own CSS to adjust the position and style of the image to meet your own needs.

add_action('geodir_after_listing_post_title', 'avatar_geodir_after_listing_post_title');
function avatar_geodir_after_listing_post_title($view, $post) {
	$author_id = $post->post_author;
	$author_link = get_author_posts_url($author_id);
	$entry_author = get_avatar( $author_id, 60 );
	echo sprintf('<div class="author-avatar"><a href="%s">%s</a></div>', esc_url($author_link), $entry_author);
}

Listing Page – Add linked business information to event listings

This Snippet will add linked business information to each event listing.

add_action('geodir_after_listing_post_title','_my_custom_geodir_event_display_link_business');
function _my_custom_geodir_event_display_link_business() {
	global $post;
	$post_type = geodir_get_current_posttype();
	$all_postypes = geodir_get_posttypes();

	if ( !empty( $post ) && $post_type == 'gd_event' && isset( $post->geodir_link_business ) && !empty( $post->geodir_link_business ) ) {
		$linked_post_id = $post->geodir_link_business;
		$linked_post_info = get_post($linked_post_id);
		if( !empty( $linked_post_info ) ) {
			$linked_post_type_info = in_array( $linked_post_info->post_type, $all_postypes ) ? geodir_get_posttype_info( $linked_post_info->post_type )  : array();
			if( !empty( $linked_post_type_info ) ) {
				$linked_post_title = !empty( $linked_post_info->post_title ) ? $linked_post_info->post_title : __( 'Listing', 'geodirevents' );
				$linked_post_url = get_permalink($linked_post_id);

				$html_link_business = '<div class="geodir_more_info geodir_more_info_even geodir_link_business"><span class="geodir-i-website"><i class="fa fa-link"></i> <a title="' . esc_attr( $linked_post_title ) . '" href="'.$linked_post_url.'">' . wp_sprintf( __( 'Go to: %s', 'geodirevents' ), $linked_post_title ) . '</a></span></div>';

				echo apply_filters( 'geodir_more_info_link_business', $html_link_business, $linked_post_id, $linked_post_url );
			}
		}
	}
}

Listing Page – Use a custom field “company logo” image as the listing thumbnail

This is a multi-step snippet that requires configuration that matches the code below. Consult a developer if it doesn’t work for you.


function modify_geodir_featured_image($post) {
	if ($post->geodir_company_logo) {
		?>
		<a class="packageplus_company_logo" href="<?php the_permalink(); ?>">
      		<img src="<?php echo $post->geodir_company_logo; ?>" />
 		</a>
		<?php
	}
}
add_action('geodir_before_badge_on_image', 'modify_geodir_featured_image');

Listing Page – Add Advanced Pagination and Show More Listings

There are a couple things a developer can do to make the Listing page fit the need.

1# Increase posts per page the WP way (Applies to Location and Listings Pages)
Use WordPress Settings to increase posts per page (Read More)

2# Customize with Advanced Pagination(Applies to Search, Location and Listings Pages)
This customization will add pagination and “Now showing 8/190” either before or after your listings.This requires a PHP Snippet, Custom CSS, and configuring a setting.
2A# Add Snippet

add_action('geodir_before_listing', 'geodir_pagination',100);

2B# Add Custom CSS

.Navi.gd-navi {display: initial !important;}

2C# Adjust Settings
Go to GD > Design > Search > Show advanced pagination details choose to show it ‘After’.

3# ServerAdmin Override for Increasing Number of Listings Shown(Caution! Applies to Listing and Search Pages)
This Member snippet will override WP settings for minimum posts to show. It is not recommended but, it works, and should be used with great caution and with the knowledge that is may increase load times. (Read More)

4# Inform Visitors with Custom Text Using Translation
You can use translation to change text that you see in the GD content areas. Follow the translation instructions at the link to find text strings, and rewrite them to give your users more information about what they are seeing (Read More)

Listing Page – Sort Listings by ‘Featured’and then ‘Overall Rating’

// Sorting the listing page results by featured & rating.
function _gd_custom_sort_by_featured_and_rating( $orderby, $sort_by, $table ) {
    if ( $sort_by == 'is_featured_asc' && !empty( $table ) ) {
        $orderby .= " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, ";
    }

    return $orderby;
}
add_filter( 'geodir_posts_order_by_sort', '_gd_custom_sort_by_featured_and_rating', 5, 3 );

Detail Page – Remove the link to the lightbox from an image upload

function gd_strip_link_from_company_logo($html) {
	global $post;
	//$html = preg_replace('/<a href="(.*?)">(.*?)</a>/', "\1", $html);
	$html = '<img src="'.$post->geodir_company_logo.'" class="gd_company_logo_img" alt="" />';
	return $html;
}
add_filter('geodir_show_geodir_gd_bus_logo', 'gd_strip_link_from_biz_logo');

Detail Page – Change the output for “Category”and”Tags” on the detail page

add_filter('geodir_details_taxonomies_output', 'geodir_details_taxonomies_output_custom', 10, 3);
function geodir_details_taxonomies_output_custom($taxonomies, $post_type, $listing_label) {
	$new_tax = array();
	foreach ($taxonomies as $key => $tax) {
		$label = geodir_ucwords($listing_label);
		$tax = str_replace("$label Category:", "", $tax);
		//$tax = str_replace("$label Tags:", "", $tax);
		$new_tax[$key] = $tax;
	}
	return $new_tax;
}

MapBubble – Make the telephone number a clickable link

add_filter(‘geodir_map_bubble_tel_linkable’, ‘__return_true’);

Detail Page – Combine custom fields into the profile tab with layout elements

add_action('geodir_before_description_on_listing_detail', 'gd_profile_custom_content');
function gd_profile_custom_content() {
	global $post;
	?>
	<div class="gd_profile_custom_content_wrapper">
		<div class="column1">
			<div>
				<?php echo geodir_get_post_meta( $post->ID, 'custom_field_key_goes_here', true ); ?>
			</div>
			<div>
				<?php echo geodir_get_post_meta( $post->ID, 'custom_field_key_goes_here', true ); ?>
			</div>
		</div>
		<div class="column2">
			<<div>
				<?php echo geodir_get_post_meta( $post->ID, 'custom_field_key_goes_here', true ); ?>
			</div>
			<div>
				<?php echo geodir_get_post_meta( $post->ID, 'custom_field_key_goes_here', true ); ?>
			</div>
			<div>
				<?php echo geodir_get_post_meta( $post->ID, 'custom_field_key_goes_here', true ); ?>
			</div>
		</div>
	</div>
	<?php
}

Detail Page – Snippet to substitute different category icons on the Detail page

The following snippet is an example of how to substitute a new image for the category icon on the Detail page. In this example, the term with id ‘946’ is being updated with a ‘new hospital icon.png’.
Be sure to get the verified term_id from the category page.

// Change category icon on detail page
function _gd_custom_detail_page_category_icon( $terms_icons, $term_id ) {
    if ( ! empty( $terms_icons ) && ( geodir_is_page( 'detail' )  || geodir_is_page( 'preview' ) ) ) {
         // $terms_icons['TERM_ID'] = 'CATEGORY ICON URL';
         $terms_icons['946'] = 'http://mysite.com/wp-content/uploads/2018/01/new-hospital-icon.png';
    }
    return $terms_icons;
}
add_filter( 'geodir_get_term_icons', '_gd_custom_detail_page_category_icon', 10, 2 );

Detail Page – Add HTML elements at the top of the More Info tab

function geodir_before_post_info_content() {
    echo "<h2>Certifications</h2>";
}
add_action('geodir_before_post_info_tab_content', 'geodir_before_post_info_content');

Claim Listings – Redirect member claiming a listing to listing page, instead of confirmation page

function _wpi_gd_custom_redirect_to_listing_after_claim( $redirect, $gateway, $args ) {
    if ( function_exists( 'geodir_get_invoice' ) && !empty( $args['invoice_key'] ) && ( $invoice_ID = wpinv_get_invoice_id_by_key( $args['invoice_key'] ) ) ) {
        if ( $gd_invoice_ID = geodir_wpi_to_gdp_id( $invoice_ID ) ) {
            if ( ( $gd_invoice = geodir_get_invoice( $gd_invoice_ID ) ) && ( $invoice = wpinv_get_invoice( $invoice_ID ) ) ) {
                if ( !empty( $gd_invoice->post_id ) && $gd_invoice->invoice_type == 'claim_listing' ) {
                    $redirect = get_permalink( $gd_invoice->post_id );
                }
            }
        }
    }

    return $redirect;
}
add_filter( 'wpinv_success_page_redirect', '_wpi_gd_custom_redirect_to_listing_after_claim', 10, 3 );

Detail Page – Set the Category Image as the visible default featured image on listings without images

add_filter('geodir_details_default_image_show','__return_true' );

Please log in to rate this.
0 people found this helpful.


Category: Customizing your GeoDirectory site

← FAQs