Implementing the lightbox effect into Genesis Simple Filter Plugin

Lightbox effect into Genesis Simple Filter Plugin

For lightbox effect I’m using the Easy Fancybox plugin. Download the plugin from WordPress plugin’s repository and activate on your server.

If you have not Genesis Simple Filter plugin then you can buy it from here and setup it on your server.

After activating the plugins you will follow the following process:

1. First creating a JS file

Create a new file “gsf-fancybox.js” and upload it into your childtheme/js folder. Now add this following code:

function popupContent( post_id ) {
  var data = {
    "action"  : "popup_content",
    "post_id" : post_id 
  };, data, function(response) {
    if( response ) {
      jQuery("#fancyboxID-" + post_id).html( response );

2. Enqueuing this JS file

I’m enqueuing this JS file for my filter page only. So file will only load when you will visit the filter page. Add this small snippet in your functions.php file.

//* Enqueue gsf-fancybox.js file
add_action( 'wp_enqueue_scripts', 'gsf_fancybox_scripts' );
function gsf_fancybox_scripts() {
  global $post;
  $page_tpl = get_post_meta( $post->ID, '_wp_page_template', true );
  if ( 'page' == $post->post_type && in_array( $page_tpl, array( "templates/page-gsf.php", "templates/page-gsf-horizontal.php" ) ) ) {
    wp_enqueue_script( 'gsf-fancybox', get_stylesheet_directory_uri() . '/js/gsf-fancybox.js', array(), CHILD_THEME_VERSION, true );
    wp_localize_script( 'gsf-fancybox', 'FB', array( 'ajaxurl' => admin_url('admin-ajax.php') ) );

3. Removing the permalink from Post Title and adding inline content div

//* Removing default hook
remove_action( 'gsf_entry_content', 'gsf_post_content', 12, 1 );

//* Removing the permalink from title and adding inline content div
add_action( 'gsf_entry_content', 'gsf_post_content_with_lightbox_link', 12, 1 );
function gsf_post_content_with_lightbox_link( $gsf_options ) {
  printf( "\t\t\t\t<div %s>", genesis_attr( 'entry-content' ) );

  //* Adding inline content div
  echo '<div style="display:none" class="fancybox-hidden">
          <div id="fancyboxID-' . get_the_ID() . '" style="width:750px;height:525px"></div>
       </div>' . "\n";
  echo "\n\t\t\t\t\t" . '<div class="overlay-effect">' . "\n";
    echo "\t\t\t\t\t\t";
    printf( "\n\t\t\t\t\t\t<h2 %s>\n", genesis_attr( 'entry-title' ) );        
    printf( "\t\t\t\t\t\t\t" . '<a onclick="%s" title="%s" href="#fancyboxID-' . get_the_ID() . '" class="fancybox-inline">%s</a>', 'JavaScript: popupContent('. get_the_ID() .');', the_title_attribute( 'echo=0' ), get_the_title() );        
    echo <div style="display:none;"> <a href="">343333</a> <div &quot;\n\t\t\t\t\t\t&lt;/h2&gt;\n&quot;;
    echo &quot;\t\t\t\t\t\t&quot;;
  echo &quot;\n\t\t\t\t\t&quot; . '&lt;/div&gt;&lt;!-- /.overlay-effect --&gt;' . &quot;\n&quot;;
  echo &quot;\t\t\t\t&quot; . '&lt;/div&gt;&lt;!-- /.entry-content --&gt;' . &quot;\n&quot;;

<strong>**</strong> Add this snippet in your functions.php file

<h2>4. Populating lightbox content</h2>

Lightbox content is populating via AJAX. I am using <a href="" target="_blank">wp_ajax_</a> action which is inbulit into WordPress. Add this code in your functions.php file.

add_action( 'wp_ajax_popup_content', 'popup_content' );
add_action( 'wp_ajax_nopriv_popup_content', 'popup_content' );
function popup_content() {
  $post_id = $_POST['post_id'];
  $post = new WP_Query( array( 'post_type' =&gt; 'listing', 'p' =&gt; intval( $post_id ) ) );
  if( $post-&gt;have_posts() ) {
    while( $post-&gt;have_posts() ) {
      echo '&lt;div class=&quot;entry-content&quot;&gt;' . &quot;\n&quot;;
        $img = genesis_get_image( array(
    			'format'  =&gt; 'html',
    			'size'    =&gt; 'feature-wide',
    			'attr'    =&gt; array ( 'alt' =&gt; get_the_title() ),
    		) );
  		  if ( ! empty( $img ) )
          printf( '%s', $img );
      echo '&lt;p&gt;' . do_shortcode( '[property_details]' ) . '&lt;/p&gt;';
      printf( '&lt;p style=&quot;text-align:center&quot;&gt;&lt;a class=&quot;button&quot; href=&quot;%s&quot;&gt;%s&lt;/a&gt;&lt;/p&gt;', get_permalink(), __( 'View Listing', 'winning' ) );
      echo '&lt;/div&gt;' . &quot;\n&quot;;

  //* reset query

popup_content() function is fetching the content from Listing Post Type. Because I'm using the Winning Agent Pro theme and AgentPress Listings plugin . You will modify this custom query as per your requirement.

See the live demo here.

Share This Article

Subscribe Membership Plan ($9.99/mo)

  • Get full access to all premium tutorials
  • Get Support for the posted content
  • Request for specific how-to tutorials
  • Cancel the subscription at anytime

Reader Interactions

Leave A Reply

Your email address will not be published. Required fields are marked *