
Recently, someone left a comment on how to create a mashup page with a map of all your posts. It is something I know a lot of people ask how to do so I have written a ‘how to’ create a map of all posts template tutorial.
1. Create a Template
Create a new template file in your theme directory. The best thing to do is to create a duplicate of page.php and call it something like “map-archive.php”. In the new template file define the template name:
1 2 3 4 5 | <?php /* Template Name: Map Archive */ ?> |
2. Get your posts
At the beginning of the template, underneath the template name, create a post query according to what you want to show on the map and assign it to the global $posts variable. For example the following query would get ALL your posts:
6 7 8 9 | <?php global $posts; $posts = get_posts('numberposts=-1'); ?> |
3. Add your Header and Footer
Add in the header and footer into the template and any other HTML layout required for your site – you could refer to your main page.php template.
10 11 12 13 14 15 16 17 18 | <?php get_header(); ?> <div id="content" class="widecolumn"> <h2>Map Archive:</h2> // We're going to put our map code here... </div> <?php get_footer(); ?> |
4. Insert the WP Geo map template function
Call the $wpgeo->categoryMap(); template tag in your template code to show the mashup map.
<?php if ( isset($wpgeo) ) $wpgeo->categoryMap(); ?>
The best place to insert the above function is just above the the WordPress the_content() function. In most themes this will display below your page title and above any content you write (see below).
5. The Final Template…
…should look a bit like this (although it will vary depending on the theme you’re using):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?php /* Template Name: Map Archive */ ?> <?php global $posts; $posts = get_posts('numberposts=-1'); ?> <?php get_header(); ?> <div id="content"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><?php the_title(); ?></h2> <div class="entry"> <?php if ( isset($wpgeo) ) $wpgeo->categoryMap(); ?> <?php the_content('<p class="serif">Read the rest of this page »</p>'); ?> </div> </div> <?php endwhile; endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> |
Simply create a page and apply this template to show the map.
How can you specify the size of the map?
I see now that the map gets its size from the default under the wp-geo settings in Wordpress.
@Chas – Yes, I will be adding options so your can override these settings on a map by map basis in the future.
Hi,
This is great. It does what I was trying to do with the Geotag pluging (which didn’t work for me at all).
Is there a way to pull out a map with posts from one specific category?
Thanks in advance,
Greg
I think you should be able to change
$posts = get_posts(‘numberposts=-1′);
to
$posts = get_posts( ‘category=1&numberposts=-1′ ); ?>
and put whatever catergory number in there that you want
Hi there,
I am very keen to see WP become a spatially-enabled CMS. Are there development projects you know of that aim to allow for the drawing of polylines and polygons and/or shapefiles using the Google API?
Thanks!
OK I’m halfway where I need to be.
The problem I have now is that the map only outputs as many markers as there are in the “posts per page” setting in the options.
I’ve been trying all sorts of custom queries and hacks to the plugin page to try to get it to read all posts but I’ve had no joy.
How can I get it to bypass the post count set in the “Reading” panel?
Hi,
how to make this work in the sidebar?
go to the Appearance>Widgets section and drag the “WP Geo” widget into your sidebar.
that is so useful, definitely gonna try on my website. thanks!
I’m very excited about this plugin, and most of it is working great for me. I’m having a problem with the page template however. My page is displaying the map just fine, but then below it displays the most recent post for some reason (instead of the content of the page). I’ve been removing and replacing sections of the code in order to find the offending line, but so far without any luck. I’m not great with the php so if you have any suggestions that would be wonderful. Thanks!
Hello Ben, great work.
I have the same problem than Mr Brainz “The problem I have now is that the map only outputs as many markers as there are in the “posts per page” setting in the options.”
Any idea?
Thanks and congrats
Nils
Try adding ‘posts_per_page’ into the query as below (please note, I haven’t tested this):
$posts = get_posts( 'category=1&numberposts=-1&posts_per_page=-1' );All posts appears well on the google maps when I create a new page like you explained in this post but not in the widget maps on the right in the sidebar… it just displays the markers relatives to the N° of posts within the same page.
I am not sure I understood your last reply. Have you have a solution to display ALL posts markers on the sidebar map?
Thank you very much!
If you edit the wp-geo-widget.php file in the wp-geo plugin folder, scroll down to line 181 where you will find the function ‘add_map’.
Add in the ‘get_posts’ bit as follows:
function add_map($width = '100%', $height = 150, $maptype = '', $showpolylines = false){
global $posts, $wpgeo;
$posts = get_posts( 'numberposts=-1&posts_per_page=-1' );
See if that works…
thats what i want to do as well
but when i try what ben suggested i get the map alright but all my posts pages show only the last post instead of the one on the adress bar ?!
simple blogger here, just gathering practical info off the web without actually being able to use php.
and the plugin is exactly what i was looking for when -recently- starting blogging, thank you thank you thank you
ok i had someone do it for me
so in case anyone else has the same issue, what he did is to remove the (..global..) $posts part while adding what ben posted
in the end it looks like
function add_map($width = ‘100%’, $height = 150, $maptype = ”, $showpolylines = false)
{
global $wpgeo;
$posts = get_posts( ‘numberposts=-1&posts_per_page=-1′ );
Great! You are the man!
It works perfectly, THX
I have almost the same problem as Matt Holmes.
The maps shows nicely with all the locations on it.
But below it shows twice the most recent post instead of the information I wrote on the page form.
I know nothing about PHP so I am complete clueless here.
Rob.
This feature works great by the way. But is there a way to have each marker link to the associated post? It’s great to be able to see each post on the map but frustrating that you can’t link to them.
please disregard my last comment. I just noticed that this feature is working if you click on a marker. my host was just running so slowly that i did not notice it working.
great work!
This plug-in is amazing!
One feature I’d love to see is the ability to specify the center point on a map on the initial view. That, plus the zoom level, will let me specify exactly how the map will look before the user has the chance to play with it.
I am using this on my home page to indicate locations of various blog postings, but it is centered on Asia, and I’d prefer that the map be centered on the Atlantic Ocean.
Any chance anyone has figured out how to do this now?
When I use this code, it still displays the posts that are just listed in the normal Loop.
I even tried using this code, but then it just displays one map and then all of the rest of the posts are hidden. It’s as if it is trying to display a map for each post, instead of getting the map info and dropping it into one single map. HELP!!!?!?!?!:
query(‘numberposts=-1cat=239&posts_per_page=-1′); ?>
have_posts()) : $allreviews->the_post(); ?>
categoryMap($allreviews); ?>
it’s also probably helpful to paste the code properly:
query('numberposts=-1cat=239&posts_per_page=-1'); ?>
have_posts()) : $allreviews->the_post(); ?>
categoryMap($allreviews); ?>
Thanks for the detailed information. I have been able to integrate the map into my website very nicely.
I think a cool feature would be thumbnails- when you hover over the marker if a thumb is associated it will show both the title and the thumbnail. Might be good if Media Galleries in 2.9 ever comes out.
Thanks for the support. I just donated. (I was keeping my fingers crossed on the conversion amount into dollars.)
Hi Chas, thanks for the donation.
I quite like the idea of thumbnails. The ability to add a thumbnail to a post will definitely be in WordPress 2.9 so I may consider using that functionality for WP Geo.
Im having trouble the the links not updating on the map when the permalink is changed…
It seems the “guid” is the link its getting it from but now it doesn work once you change the permalink, dont really know much about the guid link in wordpress. whats the difference in that and the permalink.
Anyone shed light on this problem
Hey!
I want to get the Google mashup Map embedded in the footer of my site. Can someone please guide me on how to go about doing the same.
Thanks
Hi, i’m developing a website for my MA project, and WP Geo is one of the most important features i’m using. But i have a problem: i changed a template inserting the categoryMap(); ?> line in it and the map appears perfectly. But since the website is in a subdomain of my server, when i click in the markers, it will use the main domain adress. Check it at http://hashbrum.co.uk . thank you and congratulations in such a simple and useful plugin.
Try downloading the latest Development Version at the bottom of this page.
That might fix it.
Awesome,it works like a charm. We’ll have to write a report about how we built the website, I’ll make sure WPGeo gets a whole lot of praise, our idea could not happen without it. Thank you so much for your help.
Thanks Alexandre, Did you find that WP Geo was lacking any features or is there anywhere where you could suggested improvements?
Hi Ben, sorry for taking this long to reply. I discussed the issue with my colleagues and we came with two suggestions that i think are possible to do:
The first one would be to have different and costumizable markers for each category. We can already substitute the ones there, and i think WPGeo separates markers by category already.
The second is to have an option to insert a thumbnail and a small text when we hover the markers in the map. If you see our website, we have a big map, and the title is not enough. With that i’d ditch the front page posts, and leave it to widgets, titles and the map only.
But there are other things i’d really like to have, but i’ve been so busy these days i can’t even have a clear explanation for what i’d like to have. One of them would be a back office form to input data into the map, like feeding it from a spreadsheet, but that is complicated.
Anyway, WPGeo is working just fine, and it’s really useful, and one of the star features on our website. Thank you for developing it. If you want to further discuss this, send me an email, or let me know if you’ve updated this conversation. Keep up the good work.
Thanks Alexandre,
I will add some of your suggestions to the list and hopefully I might have time to tackle them at some point.
- Ben
I’ve been able to get the map up, but instead of the title of the page being shown it uses the title of the most recent post. How do I fix this?
This is not working for me.
First of all, get_posts(‘numberposts=-1′); is only giving me one post, not all, no matter what I try.
When I switch to query_posts, it works, but it shows the map at the top of all my posts AND a map for each one of my posts below:
http://ccptr.scottelkin.com/find-a-rehab-specialist/
How can I just show a map at the top, and no map for each one of my posts?
Sorry, I put the wrong link:
This is the page I made as your above instructions. The other was just a category page.
http://ccptr.scottelkin.com/find-a-rehab-specialist/
hiho
i have the same problem…
we are making a page for a university project, and i made a test-blog to try everything before i do it on the real blog.
i did everything as it was described here but i always get two maps where only one map (with the markers of all posts) should be…
would be nice if i could get help?!
GERNOT
Hi
Thanks for this plugin, it has been working nicely for me so far. I have created a map page showing all my posts with GPS coords.
http://ossum.co.za/maps/
Now I want to add a link at the bottom of each post, which will take the reader to the correct location on the map of all posts. Is that possible? I can’t seem to think of a way.
I imagine there might be a way to set the default location of the map, on clicking the link?
I’m using your great plugin to place my recommendations on the map: http://urbankid.ro/evenimente/targul-carturestilor-303
I use the WP-Geo settings to size the map at width: 100% and height: 240px
Reading this article, I managed to create a map template so that I can display all my posts (with GEO information) on a map: http://urbankid.ro/harta
How can I set a different height for this map? (http://urbankid.ro/harta)
Thanks!
Bob
Try the following:
$wpgeo->categoryMap('height=500');works like a charm. thanks a lot for your fast support!
looking forward for next version of the plugin – custom markers/category will be very helpfull
Hi,
I successfully implemented this plugin on my website. Works really well and can highly recommend it.
However the RSS feed for posts stopped working with the errors given below for Chrome and IE respectively.
It is the left one of the two bright pink feeds in the header.
It stopped working, irrespective of whether “Feeds”, “Add geograpic information” is selected in the Control Panel.
Error messages :
CHROME
++++++
This page contains the following errors:error on line 30 at column 16: Namespace prefix georss on point is not defined
error on line 36 at column 66: Namespace prefix geo on lat is not defined
error on line 41 at column 16: Namespace prefix georss on point is not defined
error on line 48 at column 66: Namespace prefix geo on lat is not defined
error on line 55 at column 16: Namespace prefix georss on point is not defined
error on line 60 at column 65: Namespace prefix geo on lat is not defined
error on line 67 at column 16: Namespace prefix georss on point is not defined
Below is a rendering of the page up to the first error.
Internet Explorer
+++++++++++++++++
Reference to undeclared namespace prefix: 'georss'.Line: 30 Character: 17
-22.375753804739844 18.952263593673706-22.37575380473984418.952263593673706
Regards,
Hey!
Thanks for the great plugin. I wish to know if it is possible to do the following:
1. Make a Mashup Google maps of all the Geo-Tagged Pages as well as posts.
2. I have created a Mashup of Google Maps using the above instructions but it shows the header of the page too. I just want the mashup map which I want to embed to the footer of the site.
Any clue on how to go about doing the same.
Thanks,
Nishit
has anyone been able to find out how to geo-tag posts as well as pages in this way? I am trying to figure out a way but it shows only geo-tagged posts.
using
creates a template page with the header of the page too along with the map. is there any way to avoid the header. Coz if I try to cut this line out, it doesn’t show me the map