Home › Forums › MapPress Support › Mashup Popup template
- This topic has 21 replies, 2 voices, and was last updated 3 years, 10 months ago by
Chris.
-
AuthorPosts
-
April 30, 2019 at 6:35 am #18269
Hi Chris,
I’m trying to edit the template for POI mashup.
here is my code
{{{poi.title}}}
{{{poi.thumbnail}}}
{{poi.props.annonce_surface}} m²
{{poi.props.annonce_chambres}} chambre(s)
{{poi.props.annonce_sdb}} SDB
{{poi.props.annonce_prix}} €I would to like to change poi.props.annonce_prix with PHP CODE :
€
Thanks for your help
April 30, 2019 at 6:42 am #18273Hi,
You can do calculations, but you’ll need to pass the resulting value to the template. There are two ways to do this:
1) Calculate the value when a post is saved (using the WP ‘save_post’ action). Store the result in a custom field. Then, you can display the custom field in the template.
2) There’s a MapPress filter to do these calculations whenever the map is displayed. This should get you started if you want to take that approach:
https://mappresspro.com/mappress-documentation/#toc-mappress-templatingMay 15, 2019 at 4:37 am #18312Hi Again Chris,
Is it possible to display a custom field is not empty <i class=””fal” aria-hidden=””true””></i> {{poi.props.annonce_surface}} m²
For the calculation stuff, i don’t see the <code class=”prettyprint prettyprinted”><span class=”pln”>mashup</span><span class=”pun”>-</span><span class=”pln”>tmpl</span><span class=”pun”>-</span><span class=”pln”>popup</span><span class=”pun”>.</span><span class=”pln”>php</span> file ?
Could you help me on this, thank you
May 15, 2019 at 4:46 am #18313Hi,
The templates are editable via the MapPress settings screen. They’re saved in your theme directory, and the originals are in the /templates directory of the plugin. There’s general information about this in the MapPress documentation.
I think you are asking to display a field only if non-empty. For that, you would need some javascript in the template. You can do a simple if statement by using three braces:
{{{ (poi.props.annonce_surface) ? poi.props.annonce_surface : 'empty'}}}
Or, make a conditional block using ‘<#’ and ‘#>’ around the JavaScript parts:
<# if (poi.props.annonce_surafce) { #> <i class=””fal” aria-hidden=””true””></i> {{poi.props.annonce_surface}} m² <# } #>
May 15, 2019 at 5:37 am #18314Hi Chris,
That works perfectly. Thanks for your quick help.
I don’t understand about point 2 on calculations ?
Could you please give me an example.
Many thanks
May 15, 2019 at 5:37 am #18315If calculation is not possible, i just need another function.
if a custom_post_type is from taxonomy value i need to add text to price label
– location i need to add / month
– summer location /night.
Is it possible to add this to the mashup-popup template ?
<span class=”price label label-warning”> {{poi.props.annonce_prix}} € <?php if ( has_term( ‘location’, ‘offre’ ) ) echo ‘<small>/ mois</small>’; ?> <?php if ( has_term( ‘location-saisonniere’, ‘offre’ ) ) echo ‘<small>/ nuit</small>’; ?></span>
Thank you
May 15, 2019 at 5:45 am #18316I’m not sure if it’s clear, but PHP code can’t be used for calculation in the template itself. The templates use JavaScript, and they only execute when a popup is displayed.
So, using has_term() in the template won’t do anything useful. Instead, you need to do the calculations for each post using the mappress_poi_props filter. The results are then passed to the template for display using the poi.props array.
There’s an example of using the filter to pass a custom value to the template here in the MapPress documentation:
https://mappresspro.com/mappress-documentation/#toc-mappress-templating
May 16, 2019 at 4:12 am #18317Hi Again Chris,
Thanks for your reply,
I just want to add custom text depending to the taxonomy of the post.
Can we retrieve taxonomy ID or slug ?
{{poi.props.annonce_prix}} € (ADD /month or /night)
how can i achieve this, please ?
Thanks
May 16, 2019 at 4:12 am #18318Hi again Chris,
Sorry for all my questions but i modified the price value to a function so i can display the price easier on the website.
Is it possible to pass the function on the POI template ?
function annonce_post_price(){ ?>
<span class=”price label label-warning”> <?php $price = annonce_detail(‘annonce_prix’); echo number_format( $price, 0, ‘,’, ‘ ‘ );?> € <?php if ( has_term( ‘location’, ‘offre’ ) ) echo ‘<small>/ mois</small>’; ?> <?php if ( has_term( ‘location-saisonniere’, ‘offre’ ) ) echo ‘<small>/ nuit</small>’; ?></span>
<?php }Thanks
May 16, 2019 at 4:15 am #18319Hi,
Have you read the documentation yet? There’s an example there of using the PHP filter to pass a value to the template.
In this case, you would use that filter to pass the result of your function to the template as a property, then display that property in the template.
May 17, 2019 at 3:33 am #18321Hi Chris,
Are you talking about this functionnality :
<?php
function myfilter($props, $postid, $poi) {
$props[‘message’] = “Hello from post ” . $postid;
return $props;
}
add_filter(‘mappress_poi_props’, ‘myfilter’, 10, 3);
?>Thanks
May 17, 2019 at 3:43 am #18322Yes, but you would use your calculation to return the value. It would look something like this (this is just pseudo-code – I haven’t tested it):
function myfilter($props, $postid, $poi) { $price = annonce_detail('annonce_prix'); $html = number_format( $price, 0, ',', ' ' ) . ' € '; if ( has_term( 'location', 'offre' ) ) $html .= '<small>/ mois</small>'; if ( has_term( 'location-saisonniere', 'offre', $postid ) ) $html .= '<small>/ nuit</small>'; $props['prix'] = $html; return $props; }
May 20, 2019 at 3:38 am #18325Hi Chris,
Thanks for the example.
I tried your code who it seemed to be OK but it returns nothing… no value.
I tried replacing $price value with $price = get_post_meta( $postid, ‘annonce_prix’ );
Do you have an idea what is the problem?
Thanks in advance for your help
May 20, 2019 at 3:41 am #18326Hi,
I don’t know what the problem is, but I can’t test with your data. One thing I can suggest is just to return some text and make sure it’s displaying in the template. Once you get that working you can try to debug the other code.
For example, replace this:
$props['prix'] = $html;
with:
$props['prix'] = 'TESTING';
Once that’s working, you can add the other lines one by one to find the problem.
May 22, 2019 at 4:26 am #18329Hi Chris,
Thanks for your feedback,
php function number_format doesn’t work it returns no value.
Here is my new code.
function myfilter($props, $postid, $poi) {
$html .= ‘<span class=”price label label-warning”>’;
$price = get_post_meta( $postid, ‘annonce_prix’ );
$html .= $price .’ €’;
if ( has_term( ‘location’, ‘offre’, $postid ) )
$html .= ‘<small>/ mois</small>’;
if ( has_term( ‘location-saisonniere’, ‘offre’, $postid ) )
$html .= ‘<small>/ nuit</small>’;
$html .= ‘</span>’;
$props[‘prix’] = $html;
return $props;
}Now it returns array for $price value & not displaying HTML tags
Do you have an idea of the problem ?
Many thanks for your help.
-
AuthorPosts
- You must be logged in to reply to this topic.