Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattpramschufer/deda3eca703142bb3467190d883326bd to your computer and use it in GitHub Desktop.
Save mattpramschufer/deda3eca703142bb3467190d883326bd to your computer and use it in GitHub Desktop.
Simple shortcode to display featured listings on GD Directory Archive Pages
<?php
/**
*
* @wordpress-plugin
* Plugin Name: GeoDirectory Extras
* Plugin URI: http://emoxie.com
* Description: Various extra functions for GeoDirectory
* Version: 1.1
* Author: Matt Pramschufer
* Author URI: http://emoxie.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
add_shortcode('gde-featured', 'process_gde_featured_shortcode' );
function process_gde_featured_shortcode(){
global $wpdb;
$category = get_queried_object();
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}geodir_gd_place_detail WHERE `featured` = 1 AND FIND_IN_SET(" . $category->term_id . ", `post_category`) ", OBJECT );
$uploads = wp_upload_dir();
$upload_directory = $uploads['baseurl'];
$styles = '<style>.gde-grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-gap: 10px;
align-items: stretch;
}
.gde-grid-item h4 {
font-family:Playfair Display !important;
margin-bottom: 0
}
</style>';
$listings = '<div class="gde-grid-container">';
foreach($results as $listing){
$listings .= '<div class="gde-grid-item">
<a href="' . get_the_permalink($listing->post_id) . '" style="min-height:200px; background-image: url(' .$upload_directory . $listing->featured_image . '); background-size: cover; background-position:center center; display:block;"></a>
<h4 class="tdm-title tdm-title-xsm"><a href="' . get_the_permalink($listing->post_id) . '">' . $listing->post_title . '</a></h4>
</div>';
}
$listings .= '</div>';
return $styles.$listings;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment