KML Description with Image PostThumbnail
-
Hi,
I create a function to generate all <Placemark> item.
Title is ok,
Description (> get_the_content_feed + the_permalink_rss) works but i would like to put the PostThumbnail to make a better infoBox…
http://www.ddworldtrip.com/wp-content/themes/sahifa-child/customfeed/mapscheckinkml.php
I tried to encode or decode but nothing works…Any suggestion ?
Thanks
-
G’day popsantiago,
Looking at the checkin page, the Paris link has that post thumbnail. It just needs a
<br/>
or something, or wrap the description in<p>
to make it a separate paragraph. Alternatively, you could use CSS to style the image if you give the image a class.Or am I missing something?
cheers,
RossHi Webaware,
Very fast reply as always !
Sorry for that… was 3AM in France and my mind wasn’t be fresh. I clicked on a marker without postthumbnail … CQFD ! 😉
At the morning it’s better, that works!
I tried to put some CSS to customize infoBox, <p> works like you tell me, but <p class=”post-tag”> class disappear after script…
http://www.ddworldtrip.com/wp-content/themes/sahifa-child/customfeed/mapscheckinkml.php
Post script : http://www.ddworldtrip.com/checkin/
(Click on Paris to inspect image 😉 Joke)Another question more fore the safety… maybe you can hell me
I used the Tutorial https://developers.google.com/kml/articles/phpmysqlkml?hl=fr#outputkml to make my dynamic kml (Place in my Child Theme).
First i get the WP_query undefined error, after checking on Forum, i add a line before
require_once( $_SERVER['DOCUMENT_ROOT']. '/wp-blog-header.php' );
Is it safe ? And do you know how can i make better thingsThanks you
G’day popsantiago,
Ah, I forgot that Google strips the classes from the KML. That’s just rude! Oh well. At least you got it working and looking pretty good!
To your other question, no, it isn’t safe. Better would be to use the constant
ABSPATH
which points at the WordPress root folder, best is to not load WordPress yourself; hook into it from a plugin or theme using action and filter hooks.edit: I’m stupid, you won’t have ABSPATH until you load WordPress; duh!
You would be best served by writing a simple plugin to generate your KML dynamically. You can use the AJAX API to return your KML, and it then goes through WordPress but without all the bother of loading the whole front end. You can then use the WordPress $wpdb object to query the database, or even use WordPress queries if the data are in posts or postmeta.
(Actually, you could use the AJAX API from your functions.php in your theme, but I still recommend you write a plugin — keep functionality separate!)
Incidentally, I reckon using the DOM to write XML is rather ugly; much easier to use XMLWriter — it’s certainly my preferred tool for that job!
cheers,
RossHi webaware !
Ok i will let infobox like that 😉 it’s not uggly
Second work will be too harder for me… but i will try it !
Was easer for me last night working with echo php kml because i got a georss tuto to get the query and item. But you are right, i will be use the DOM.
Thank you
G’day popsantiago,
If nothing else, take your code that works just fine, and wrap it up in a function you call from the AJAX API. You can hook that into your theme’s functions.php file very easily. No hard work there, honest! Something like this:
add_action('wp_ajax_ddworldtrip_maps_checkin', 'ddworldtrip_maps_checkin'); add_action('wp_ajax_nopriv_ddworldtrip_maps_checkin', 'ddworldtrip_maps_checkin'); function ddworldtrip_maps_checkin() { // your existing code here... }
Done.
I recommend you use XMLWriter because it handles all the tricky bits of escaping special characters for XML. Easier than using the DOM, and safer than directly echoing KML. Also easier to balance open and close tags 🙂
cheers,
RossHey webaware
I’m really bad with php function…
I do the function ddworldtrip_maps_checkin()
But if i put :
echo do_shortcode('[flexiblemap src="'.ddworldtrip_maps_checkin().'" width="100%" height="400"]');
Checkin page write the kml… http://www.ddworldtrip.com/checkin/
Any idea ?
G’day popsantiago,
Sorry, I should have been more explicit. You change the src link to this:
http://www.ddworldtrip.com/wp-admin/admin-ajax.php?action=ddworldtrip_maps_checkin
Also, last line of your new function should be
die();
so that WordPress stops processing and sends your KML file.cheers,
RossReally sorry…
http://www.ddworldtrip.com/wp-admin/admin-ajax.php?action=ddworldtrip_maps_checkin
give me a ‘0’…
Can you email me your functions.php file? email address here… http://www.webaware.com.au/contact-us/
cheers,
RossHey Webaware
We are genius 😉So i got a mistake (my bad i hate copy/paste) so i write
add_action('wp_ajax_XXXX_maps_checkin', 'ddworldtrip_maps_checkin'); add_action('wp_ajax_nopriv_XXXX_maps_checkin', 'ddworldtrip_maps_checkin');
Not same name so that not worked.
One time solved :
Response http://www.ddworldtrip.com/wp-admin/admin-ajax.php?action=ddworldtrip_maps_checkin was good…
But http://www.ddworldtrip.com/checkin/ doesn’t work.According my first code and http://codex.wordpress.org/AJAX_in_Plugins#Ajax_on_the_Administration_Side for a PHP request the die(); is needed // this is required to return a proper result
So now it’s good and safe !
Thank you so much !
EDIT Next Step : DOM 😉
Well look at you! Seems to me that your PHP is just fine 🙂
Well done, keep going!
cheers,
RossThanks 😉
Php skills grow!One last question but not least…
Can i link the Marker selected with the loop ?
Marker 1 with Checkin 1 ?Thanks
I’m sorry, I don’t understand what you mean by that. Do you mean, show a specific marker’s info window? If that’s what you mean, then I don’t know how to tell KML to do that… maybe google for an answer on that one (there’s only so much I can know!)
cheers,
RossOk no problem.
Thanks for replies
I will check in google 😉
- The topic ‘KML Description with Image PostThumbnail’ is closed to new replies.