• Resolved samuel1mclean

    (@samuel1mclean)


    Hello everybody,
    I’m using wordpress to create a database research tool, with a relational database for naval deployment records.

    I’m using Custom pages- where everything put onto the page is in HTML-but it’s created when the page is loaded/echoed so it’s not actually in the “text box” of the page itself.

    as a result, when I put in the shortcode- it just shows up as

    `
    [leaflet-map]
    `
    I was wondering if it’s possible to use the plugin and shortcodes in this manner- obviously what I’m doing doesn’t work- but I’m not sure how to make it work? I don’t want to create one *standard* that shows up every time- basically when the page loads, it grabs a series of locations/lat/long coordinates from the database (and labels), and I run that through a foreach loop and spit out the [leaflet-marker (etc) things.

    So at the moment, they just show up as text in the html.

    also, do I need to put a [/leaflet-map] tag to end the list?

    I very much appreciate your help

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author bozdoz

    (@bozdoz)

    Hi!

    I don’t know what “Custom pages” is. Is that a plugin? I am not sure what you mean when you say everything “is in HTML” and not “in the text box”. It sounds like you’re not using WordPress (I’m sure you are; I’m just saying it doesn’t sound like it). Let me know!

    • This reply was modified 4 years, 10 months ago by bozdoz.
    Thread Starter samuel1mclean

    (@samuel1mclean)

    Hi,
    sorry.

    I am using WordPress.

    What I mean is- I’m using a custom page template (based on Bangkok Press). In this template, I use PHP/HTML to generate the content of the page- but it’s all generated when the page is loaded- so it’s not saved like a WordPress Page/Post is?

    Like on a page or post- when you use the standard interface to enter the text- it’s saved as a post, in the DB, and then when a person views that post, that content is seen. And I understand that’s where the shortcodes are usually used.

    I.. pretty much entirely bypass that.

    https://globalmaritimehistory.com/adm-8-database-project/ here’s the page I’m working on.

    if you choose “Get a Specific Report”, and then “Retrieve Whole Report” (for the first option in the dropbox) it’ll show you what my interface/page looks like- and below the table is where I input the shortcode, but it didn’t work.

    Basically what I’m trying to do is- after the report (or, maybe even, above the table with the report rows) I want to have a map so that a researcher can see all the locations where the ships were.

    I know this is a pain, but it’s easier if you see what I mean. I very much appreciate your patience.

    • This reply was modified 4 years, 10 months ago by samuel1mclean. Reason: I wanted to add one more thing
    Thread Starter samuel1mclean

    (@samuel1mclean)

    I suppose what I could do is-

    place the function which calls *the content* from the database after my HTML/PHP stuff- and in my code write to the content line for the page- but the problem with that is, it would stay there until somebody else used the page. And there would be problems if more than one researcher is using the tool at a time.

    Plugin Author bozdoz

    (@bozdoz)

    If it’s in a PHP template, then maybe what you’re looking for is do_shortcode?

    for example:

    <?php
    echo do_shortcode(‘[leaflet-map]’);
    ?>

    Plugin Author bozdoz

    (@bozdoz)

    Thread Starter samuel1mclean

    (@samuel1mclean)

    I really appreciate this.

    `
    echo do_shortcode(‘[leaflet-map]’);
    foreach( $array_of_locations as $marker)
    {
    echo do_shortcode(‘[leaflet-marker lat=’ . $marker[1] . ‘ lng=’ . $marker[2] . ‘]’ . $marker[0] . ‘[/marker]’);
    }
    `
    is what I wrote into my template, but my compiler is objecting- at the ‘.

    am I missing something here?

    Thread Starter samuel1mclean

    (@samuel1mclean)

    I updated it, now it’s

    `
    //this is using the leaflet app
    echo do_shortcode(‘leaflet-map’);
    `
    I’m not sure what the difference is-
    unfortunately, it’s still not working- it’s simply outputting

    `
    leaflet-map
    `
    on the screen.

    Could the problem be, that the leaflet functions etc aren’t being included in my page?

    Plugin Author bozdoz

    (@bozdoz)

    Both look wrong to me. It must be ‘[leaflet-map]’, not ‘leaflet-map’ (shortcodes need square brackets).

    You ended your leaflet marker shortcodes with [/marker]; maybe try this one:

    echo do_shortcode(“[leaflet-marker lat=\”$marker[1]\” lng=\”$marker[2]\”]$marker[0][/leaflet-marker]”);

    Thread Starter samuel1mclean

    (@samuel1mclean)

    Well the good news is that the map now shows up (although there’s a strange blank space on the page)

    Unfortunately, the markers aren’t working- although they’re no longer outputting just as text.
    It seems to me that the whitespace above the map is something to do with the markers- because on a report that has more lines/more markers, the whitespace is larger/ longer.

    https://globalmaritimehistory.com/adm-8-database-project/ is the link again- and if you go “Choose a Specific Report” and then the first one from the dropdown option, you can see what I mean.

    I really appreciate your help with this, I feel like we’re 98% of the way there.

    `
    echo do_shortcode(“[leaflet-map]”);
    foreach( $array_of_locations as $marker)
    {
    //echo do_shortcode(‘[leaflet-marker lat=’ . $marker[1] . ‘ lng=’ . $marker[2] . ‘]’ . $marker[0] . ‘[/leaflet-marker]’);
    echo do_shortcode(“[leaflet-marker lat=\”$marker[1]\” lng=\”$marker[2]\”]$marker[0][/leaflet-marker]”);
    }
    `
    this is my code as it stands now.

    Plugin Author bozdoz

    (@bozdoz)

    Looks like it may have to do with the smart quotes. Maybe re-type the shortcode yourself without copy/pasting.

    Here’s a normal quote: ”

    And here’s a quote copy/pasted from that shortcode: ”

    I just visited your site and I can see the console says: “illegal character”. So I’m betting it is complaining about that “smart” quote.

    Thread Starter samuel1mclean

    (@samuel1mclean)

    I re-typed the shortcode, (using my quotes) it didn’t change anything unfortunately (at least that i can tell). Tbh, I’m not sure how to use the console. (I’m fairly new at this and frankly this is the most advanced stuff I’m doing)

    Thread Starter samuel1mclean

    (@samuel1mclean)

    I”m looking at it now. Something changed… and now it works? Things are popping up anyways.

    I have to change the map so that all the markers fit (but that’s easy).

    Do you have any idea about the whitespace above the map?

    Plugin Author bozdoz

    (@bozdoz)

    Looks like some of them may have worked and some didn’t. I can see this:

    var marker = L.marker(
    [lng=,0],
    marker_options
    );

    Which looks like the lng= portion of the leaflet-marker shortcode isn’t working. Maybe there’s an entry without a longitude? Maybe it’s malformed?

    Maybe try printing out all of the $array_of_locations first to see that they all have correct data.

    Also, you can see the developer tools by going to browser options > Developer tools in most browsers (probably not internet explorer)

    Thread Starter samuel1mclean

    (@samuel1mclean)

    It looks like it’s working now- because things are in roughly the right positions?

    echo do_shortcode(“[leaflet-map fitbounds zoomcontrol]”); would this work to add the zoom controls?

    Thread Starter samuel1mclean

    (@samuel1mclean)

    I have to say- despite the difficulties (caused by me working around WordPress rather than actually using wordpress- and not knowing wordpress very well) – this is a beautifully done plugin.

    I’ll recommend it to everybody I know who does digital humanities projects with mapping.


    Is it possible that the whitespace above the map is caused by the shortcode? or is it likely something else?
    Changed here I’ve realized the problem is I was var_dumping something- with breaks- and I commented out the vardump but not the breaks- the white space is entirely my fault. (Your pluging is lovely and genius)

    One final question- is there a way to have- when multiple markers are in the same position, to have them slightly clustered in placement? (It’s fine if not, I’m just curious)

    • This reply was modified 4 years, 10 months ago by samuel1mclean.
    • This reply was modified 4 years, 10 months ago by samuel1mclean.
Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Using Leaflet on custom page’ is closed to new replies.