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”.
Here is the snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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.
Emmanuel says
Hello,
How can I show the of the title of the listing instead?
Taiwo David says
Hello thanks for the extended feature.
Please can you tell me how to add a BUTTON TEXT to a Listing?
Example: BUY NOW
SUBSCRIBE NOW
Saber says
It works very well! Thank you so much! Can you tell me how to display as follows:
-Price
– property name
-180sqft, 3beds, 2bath
-view listing
in other words
change city, state, zip by sqft, bed, bath
.Thank you so much!
Audrey Tomkiewicz says
Hi! I’m trying to have the AgentPress Listings display a slideshow instead of an image with thumbnails below, I can manage to do it through the Add Media button but I don’t like the look of the slideshow I get (black background, rounded corners, etc.). Is there a way to modify this, or a different way to insert a slideshow? Here’s what it looks like: https://gestionnordsud.wpcomstaging.com/listings/2195-rue-sylvain-1-et-demi/
Christian says
Dear, very good afternoon. I use Agentpress Pro with its agentpress listing plugins, and yesterday I am trying to modify the information in property_details, and it does not allow me to make the changes, and I cannot modify the insertion codes of maps and videos either. I have also tried to create a new property to assign the data that does not allow me to modify, but it also does not save the info in the property_details in the new property created. Could you tell me if it’s an update problem or can I solve it with some code or file? I appreciate your valuable help, and excuse my English, since I do not master it very well. Thank you very much.
Paul says
Are you getting any error message?
Justin Chia says
Hi Paul,
I’m trying to replace price with name of the property on the thumbnail of the listing, when it’s showing on the homepage?
Do you have any idea how to do it?
Thank you
http://Newcondosearches.com
Paul says
I checked your site. You already sorted out the problem.
Jeff says
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.
Paul says
Use
<br />
HTML tag for next line. Otherwise you can do it by CSS.Paul says
Hi All
I created this plugin “Extended AgentPress Listings Widget” (EAPLW) for you. It is very handy, lightweight, simple and you can easily maintain your listings now.
Plugin URL: https://paulchinmoy.com/extended-agentpress-listings-widget/
If you have any queries about this plugin then you can feel free ask via contact form.
Thanks
Chinmoy
Asri says
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
Paul says
Are you added this in style.css file?
[code lang=”css”].listing-text.new-listing{
background-color: green;
}
.listing-text.sold{
background-color: red;
}]
Asri says
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
Paul says
Your custom text is “New Listing”. James is using “Just Listed”. Here is the difference.
Asri says
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
Paul says
Hi ASRI
Try this code:
]
Asri says
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
Paul says
You need to add the css in your style.css file.
[code lang=”css”]
.property-status{
display: block;
}
]
Asri says
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
James Goodwin says
Working! quot; should be ” 🙂
Paul says
Great.
James Goodwin says
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
James goodwin says
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.
Paul says
Yes. Possible. I did it and it is working at my end.
Add the following code in your style.css file
[code lang=”css”]
.listing-text.just-listed{
background-color: green;
}
]
Add this code in your functions.php file
]
Asri says
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.
Rachelle says
This works great! Thank you so much! Can you tell me why it only works on the home page/Agent Press Featured Listings Widget and not on the Listings Archive Page? How do I modify it to work on the archive page as well? Thanks so much!
Paul says
You will edit the archive-listing.php file
Rachelle says
Hi Paul,
Thank you so much for your response. I added it to the archive-listing.php file and I must have done something wrong because it didn’t work (it worked for the home page perfectly). Do I need to use the same exact code in the archive-listing.php file? Does it matter where I add it in that file? And do I need to delete/change any code in the archive-listing.php file? Thanks so much for your help
Rachelle says
Hi Paul,
I’ve tried putting this code in the archive-listing.php file – I tried pasting at the begginning, at the end and it didn’t work, so I tried changing it from add_filter(‘agentpress_featured_listings_widget_loop’
to add_filter(‘agentpress_listing_archive_loop’ (didn’t work), and I also tried add_filter(‘listings_archive’
Is there something else about the code that I need to change to get it to work with the archive?
Thanks so much
Rachelle says
Ok I finally figured it out if anyone is interested.
It is actually the taxonomy.php file that needs to be edited. I got it to work by editing the function that was already there. Find this function
function agentpress_listing_archive_loop() {
then scroll down to where you see
if ( $listing_text ) {
$loop .= sprintf( ‘%s‘, $listing_text );
}
Then change it to
if ( $listing_text ) {
$class = str_replace( ” “, “-“, strtolower( esc_html( $listing_text ) ) );
$classtwo = ‘listing-text ‘ . $class;
$loop .= sprintf( ‘%s‘, $listing_text );
}
James Goodwin says
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.
Paul says
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
Lisa says
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
Paul says
Hi Lisa,
Thanks for your compliment.
Use BxSlider JQuery library for AgentPress listings Slideshow. See the example here.
If you need any assistance then you can feel free ask me.
Best
Chinmoy
Paul says
Hi Lisa,
This is for you 🙂
https://paulchinmoy.com/adding-carousel-slideshow-agentpress-listings-widget/
Best
Chinmoy
kyle says
Hi thanks for this how do remove the address and add other details. For example Gross Profit, Cash Flow? I list businesses for sale and business address is not public.
See my complete concern listed here
http://www.studiopress.com/forums/topic/need-help-editing-agentlisting-plugin/
Thank You
Paul says
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.