Adding Extra Features in Agentpress Featured Listings Widget

Agentpress is a popular Genesis Child theme for Real Estate sites. The theme uses a free plugin “Agentpress Listings” to list the properties and comes with 2 widgets. By default “Agentpress – Featured Listings” widget shows the price, custom text, address, city, state and zip code. Adding the following snippet to the theme’s functions.php allows the addition of an extra feature without modifying the plugin itself thus allowing the plugin to be updated. In the following example I have added the number of “bedrooms”.

adding-extra-features-agentpress-featured-listing-widget

Here is the snippet:

  add_filter('agentpress_featured_listings_widget_loop', 'gd_add_feat_bedroom', 10, 1);
  function gd_add_feat_bedroom( $loop ){
    $br = '';
    $bedrooms = get_post_meta( get_the_ID(), '_listing_bedrooms', true);
    $sing_pul = ( (int) $bedrooms > 1 ) ? 'bedrooms' : 'bedroom';
    if( $bedrooms ):
      $br = sprintf( '<span class="listing-bedrooms">%s %s</span>', $bedrooms, $sing_pul );

      $needle = "</span>";

      //find length of the needle
      $needle_len = strlen($needle);

      //find postion
      $position_num = strpos($loop,$needle) + $needle_len;

      //cut the string
      $loop = substr($loop,0,$position_num) . $br . substr($loop,$position_num);
    endif;

    return $loop;
  }

Note: Add the code in your functions.php file.

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

25 Discussion to This Post

  1. I tried the Featured Listings addition of # of bedrooms, but that text is showing up beside the price, not on the next line like your sceenshot shows. Does this code need an update for the latest version of WP? Or did I miss something? Thanks.

    • Use <br /> HTML tag for next line. Otherwise you can do it by CSS.

  2. Hi Chimnoy29,

    Sorry for asking again this time.. i want to change the button/ribbon color according to text added on “custom text” . Red to SOLD, GREEN to New Listing. Etc.. Have tried as above. Nothing changes,and no error reported.

    Anything i missed?
    Thank you in advance for the reply.
    ASRI

    • Are you added this in style.css file?

      .listing-text.new-listing{
        background-color: green;  
      }
      
      .listing-text.sold{
        background-color: red;  
      }
      • Hi Chinmoy29,
        Thank you again.You just save the day! Your next example of code added to CSS is working. Still wonder, why the first css snippet u replied to James goodwin wasnt work.
        —>
        .listing-text.just-listed{
        background-color: green;
        }

        Anyway. Thanks a bunch for help!

        ASRI

        • Your custom text is “New Listing”. James is using “Just Listed”. Here is the difference.

  3. Hi sifu,
    Thank you for the snippet of adding extra text on “Agentpress – Featured Listings” widget . I am not good in coding PHP, but i guess those feature on the snippet above for extra item with number (integer). Ex, 2, 3 of bedrooms number.
    I guess i know how to add / change Agentpress listing in the function.php and class-listing.php. I am adding __( ‘Property Status’, ‘agentpress’ ) => ‘_listing_status’, .

    The Property Status will be “For Rent” , For Sell, Etc. Instead of example above to add Bedroom, how can i show my “Property Status” value. ? Can you sifu here show me.

    ps: sorry,bad english writing there. Hope you understand.
    Thank you

    • Hi ASRI

      Try this code:

      add_filter('agentpress_featured_listings_widget_loop', 'gd_show_property_status', 10, 1);
      function gd_show_property_status( $loop ){
        $br = '';
        $pstatus = get_post_meta( get_the_ID(), '_listing_status', true);
        if( $pstatus ):
          $br = sprintf( '<span class="property-status">%s</span>', $pstatus );
      
          $needle = "</span>";
      
          //find length of the needle
          $needle_len = strlen($needle);
      
          //find postion
          $position_num = strpos($loop,$needle) + $needle_len;
      
          //cut the string
          $loop = substr($loop,0,$position_num) . $br . substr($loop,$position_num);
        endif;
      
        return $loop;
      }
      
      • Thank you sifu for the quick reply.
        I successfully added the status on list. But the added Status shows on the right side of the price. Not below the price as the above tutorial. Mind to help again?

        Thank You
        Asri

        • You need to add the css in your style.css file.

          .property-status{
             display: block;
          }
          
          • Thank you very much. It Works!
            I am new to all of this code thing and it is just wonderful to know it well. Just like a car mechanic knows why the car breakdown.

            Thanks

  4. Awesome, this makes a lot of sense. I am getting a parse error:

    Parse error: syntax error, unexpected ‘;’, expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /home/jamesg89/public_html/wp-content/themes/agentpress-pro/functions.php on line 236

    Line 236 being : $class = str_replace( "", "-", strtolower( esc_html( $custom_text ) ) );

    Cheers,
    James

  5. Yup, I am using that, I am looking to customize those spans you are talking about. For instance I am looking to code it so the span changes BG color depending on the info in the span. So if the custom text reads sold then it’s background is red etc.

    • Yes. Possible. I did it and it is working at my end.

      Add the following code in your style.css file

      .listing-text.just-listed{
        background-color: green;  
      }
      

      Add this code in your functions.php file

      add_filter('agentpress_featured_listings_widget_loop', 'gd_change_ribbon_color', 10, 1);
      function gd_change_ribbon_color( $loop ){
        $custom_text = genesis_get_custom_field( '_listing_text' );
        if ( strlen( $custom_text ) ) {
          $class = str_replace( " ", "-", strtolower( esc_html( $custom_text ) ) );
      		$loop = str_replace('listing-text', 'listing-text ' . $class , $loop );
      	}
      
        return $loop;
      }
      
      • Hi Sifu,
        i did exactly, why it does not work with me?
        Edit to given area, and upload to server. Nothing change to the color.
        Anything i missed here?

        Thank
        Asri.

  6. Great tutorials! A little feature I am looking to try and tackle is changing how the span for “Sold” shows on featured listings. For example, I want the span to be colored red if text = ‘SOLD’; I would like the span to be green if text = ‘Just Listed’, etc.

    • Hi James

      Thank you for contacting me. There have custom text field. This text is already coming on ribbon at right side corner of the image. Why are you not using that default one?

      Thanks
      Chinmoy

  7. Hi Chinmoy,

    This is a great tutorial – thank you so much! I was wondering if you happen to know whether it’s (easily) possible to turn the AgentPress listings widget into a slider. We’re trying to create a slider that showcases 6 listings at a time (2 rows of 3 listings).

    Thanks so much!
    Lisa

    • There required lot of custom coding. So Kyle HIRED ME me for this job and I fixed the problem quickly. Now his problem is RESOLVED.

Leave A Reply

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