Index

  1. Home
  2. Docs
  3. Index
  4. Data Explorer
  5. Dynamic Hyperlinks

Dynamic Hyperlinks

A dynamic hyperlink is a computed column generated on the fly. Column variables can be added to a hyperlink and are substituted on generation. Allows to add custom HTML (see icons in example below – click to enlarge).

Adding dynamic hyperlinks

Hyperlink Label

Column label in a list or on a form.

+List?

Enable if hyperlink should be shown in lists.

+Form?

Enable if hyperlink should be shown in forms.

+Window?

Enable if hyperlink should be opened in a new tab or window.

HTML

Add a URL(like https://your-domain/) or add your own HTML including one or more hyperlinks. If you just add a URL, the plugin will use the Hyperlink Label and +Windows? settings. Otherwise the plugin uses your HTML code.

Add your own HTML if you want to:

  • add multiple hyperlinks in one column
  • use icons in your hyperlinks instead of the label text
  • your own HTML to this column
Notes
  • Links are added to the end of the table or view in the Data Explorer and Data Projects
  • Links can be added on any position in the Data Publisher
Column Value Substitution

To use column values in a hyperlink simply add the column name between $$ to your URL or HTML. In the example below the variable $$id$$ is substituted with the value for column id. Column id must be a column of the table for which the hyperlink is created.

https://your-domain/service.php?id=$$id$$

Data Publisher

To add a hyperlink to a publication:

  • Edit the publication
  • Click on button “Select”
  • Add your columns and hyperlinks to the list on the right side
  • Save your publication

#macro if-then-else

Use #macro-if-then-else to add conditions to your dynamic hyperlinks. The following example shows only hyperlinks for sneakers:

#macro if "$$product_name$$" == "Sneakers"
  <a href="$$product_image$$">$$product_name$$</a>
#macro end if

The plugin also supports nested macros (see examples).

Examples of dynamic hyperlinks

https://your-domain/service.php?id=$$id$$

Adds hyperlink https://your-domain/service.php?id=123 if id = 123

<a href="javascript:void(0)" onclick="if (confirm('Search Google?')) { window.location.href='https://www.google.com/search?q=$$first_name$$+$$last_name$$'; }" target="_blank">Search Google for $$first_name$$ $$last_name$$</a>

Adds a hyperlinks which asks for confirmation and then opens a Google search with first name and last name in a new tab or window.

#macro if "$$product_image$$" != ""
  #macro if "$$product_name$$" == "Sneakers"
    <a href="$$product_image$$">$$product_name$$</a>
  #macro else
   <span>N.A.</span>
  #macro end if
#macro else
  <a href="javascript:void(0)" onclick="alert('This item is currently not available')">N.A.</a>
#macro end if

A nested if-then-else macro is used to show information depending on the column values. This can be combined with other options.

Was this article helpful to you? Yes No

16 Replies to “Dynamic Hyperlinks”

  1. Hi Peter,

    so my suggestion is: If I use a Dynamic Hyperlink and use a link like: http://127.0.0.1/wordpress/test-page/ and I want to add the column information from “my_id” then my link is: “http://127.0.0.1/wordpress/test-page?my_id=$$my_id$$” correct?

    Next I want to use the my_id information in a shortcode from a datapublisher-page to filter the table entries there. Is that even possible?
    If not, how can I use the Dynamic-Link-Information to get data from a table and display that on a custom wordpress page or post?

    Thank you so much! I have the impression that I’m missing some connections in how these value substitutions work..

    Have a nice day,
    Chiara

  2. Hi Chiara,

    Your suggestion is correct! That’s is exactly how dynamic hyperlinks (value substitutions) are meant to be use. 😉

    It should be possible to use argument my_id in your publication as well, but I haven’t tested it. Please check out this options to define an initial search on a specific column:
    https://datatables.net/reference/option/searchCols

    Within the plugin you can use filter wpda_wpdataaccess_prepare to read the url argument and write its value to a javascript variables, which can then be used in your initial search. Here is some information about filter wpda_wpdataaccess_prepare:
    https://wpdataaccess.com/2020/03/25/filter-wpda-wpdataaccess-prepare-to-add-custom-options-to-a-publication/

    In your use case you might also want to disable a global search. You can use the dom option to do this:
    https://datatables.net/reference/option/dom

    Looks like you’re building a complete application with a flow from data entry until data publication? Great! 🙂 Let me know if you help…

    Best wishes,
    Peter

    1. Good Morning Peter,

      yesterday I’ve tried to understand, how this could work out, but I didn’t made much progress.

      First question: where do I have to edit the filter wpdata_wpdataaccess? Is the filter integrated in the plugin-files somewhere or can I use it directly in the plugin-frontend on wordpress somehow?

      Second question: when I did the dynamic hyperlink with “http://127.0.0.1/wordpress/test-page?my_id=$$my_id$$” and then click on this in a row of my published table the link I get is: “http://127.0.0.1/wordpress/test-page/?my_id=$$my_id$$”. There is no value substitution happening. Do I have to add more information to the dynamic link or what is going wrong here? Is there a problem because my “test-page” is a wordpress page and has no extension “.php”?

      Thrid question: how can I then connect the filter wpdata_wpdataaccess_prepare with my publication?

      I would be so glad, if you could do a short tutorial or something to this issue. Something like “how can I add a dynamic link to a publicated table, which links to a page, where I filter data from a table and show only a picture or the price of the product and not all detail-information?”
      If you don’t have the time to do a tutorial, i totally understand that.

      Thank you sooo much for your support! Don’t know, what I would do without your constant, helpful support!

      Chiara

      1. Hi Chiara,

        Let’s start with the dynamic hyperlink. Does your table have a column my_id? The plugin will only substitute values for existing column names. If your table has no column my_id, nothing happens. Make sure your are writing an existing column name between the $$ characters. For example: use $$student_id$$ to add the student_id to your hyperlink.

        When your hyperlink points to:
        http://127.0.0.1/wordpress/test-page/?my_id=123
        you need to make sure this page exists and is able to handle argument my_id. Your hyperlink can be on the same domain or another domain. So:
        http://www.some-domain.com/index.php?my_id=123
        works as well. Your hyperlink URL does not need to have an extension .php as long as the URL is able to handle the querystring (in this case my_id=123) you are sending.

        Be carefull with the filter! The name of the filter is:
        wpda_wpdataaccess_prepare (not: wpdata_wpdataaccess_prepare)

        To add a filter, you need to put your PHP code “somewhere”. There are severals ways to do this. One of the most common ways I think is to add your code to the theme function.php file. The disadvantage is that a theme update overwrites your changes.

        I created a plugin add-on – the Code Manager – to add your own hooks and filters in such a way that it survives all types of updates (WordPress, themes and plugins). The add-on is ready, but I do not yet have a sales channel (working on it). I will need to create an instruction video for this add-on anyway, so I’ll try to create a video this week. I hope the video will help you to write your own hooks and filters.

        Best regards,
        Peter

  3. Hi Peter,

    In the example on top of this page, on the ‘Settings’ tab, an option ‘Search Settings’ is visible, which is not on my version (3.1.4) of the WP Data Access plugin.

    What I’m looking for is an example how to create an advanced search form with multiple fields. The user’s input could than be processed by a PHP-script on the server and a temporary results table could than be handled by the Data Publisher.

    However, I didn’t find out how to create search fields on a form with your plugin thus far.
    Would you be so kind to provide an example?

    Thanks in advance,
    Ike de Pagter

    1. Hi Iek,

      Sharp eyes! 🙂 I think I forgot to disable that option when I created that screenshot.

      The premium version of the plugin, coming out this month, allows to add a number of search option. The premium version is not free! If you are interested, here is a link to a video in which some of the premium search features are explained: https://www.youtube.com/watch?v=Zy_AWrULgCI

      Best regards,
      Peter

  4. Hi Peter,

    Question for you about the use “Column Value Substitution” in the context of Dynamic hyperlinks.

    The table column I’m using as the source for the substitution contains a UK post code e.g. TN21 567 (note the space character). The substitution process appears to be truncating the content immediately after the space i.e. TN21 is being returned and the 567 is ignored. Is this a feature or something I’m doing my side?

    Thanks and regards.

    Richard.

    Founder of AircraftTrafficSurvey.com

    1. Hi Richard,

      The truncation is not related to the value substitution. If the value does not fit the browser wraps it. You can prevent wrapping with CSS. For your postcode column this could be:

      table.dataTable td.postcode {
      white-space: nowrap;
      }

      Can you send me the URL if this does not work?

      Thanks,
      Peter

  5. Hi Peter,

    The following URL demonstrates the problem http://www.aircrafttrafficsurvey.com/?page_id=1303

    You will see two images of aircraft which are the hyperlinks. The first one passes the value for the Location (working) the second passes the postcode (failing i.e. gets truncated) but as you will see the postcode appears okay on the page.

    The hypertext links are as follows;

    works!

    Truncates!

    Hope this demonstrates the issue.

    Thanks and regards.

    Richard.
    Founder of AircraftTrafficSurvey.com

    1. Hi Richard,

      Thanks for your explanation! This is a completely different issue…

      Some characters in URL arguments need to be encode. A blank needs to be substituted with +

      “WV7+3JD” instead of “WV7 3JD”

      If your dynamic hyperlink html column contains a URL only, I can let the plugin do the substitution. If you are using a more complex format, you can use a view. So what do your hyperlinks look like?

      Thanks,
      Peter

  6. Hi Peter, I’ve included a new column into the table that contained the replaced space with a + for the Postcode attribute. It now works as expected. If I had tried to do the substitution using JavaScript where could I have done this? Using the Publisher Table Advanced Options or somewhere else?

    Thanks and Regards.

    Richard.

    1. Hi Richard,

      Good question! 🙂 With javascript I would suggest to use a function and do the encoding in the javascript function. You can call the javascript function from your dynamic hyperlink.

      If you are looking for a tool to add javascript functions to your page, you might want to have a look at my new plugin the Code Manager:
      https://wordpress.org/plugins/code-manager/

      Using javascript functions is documented here:
      https://code-manager.com/blog/docs/index/shortcodes/javascript-shortcodes/

      Just in case you want to use javascript in your dynamic hyperslinks… 🙂

      Best regards,
      Peter

    1. Thank you Lucas! 🙂 I changed it right away. You’ll find your contribution in the next release.

      Best regards,
      Peter

  7. Hi Peter,
    I have a database with a name column and a link column, and configure the url column as hyper link. It works. Now I would like to Bond the 2 column content, variable name and corresponding variable url’s to make pretty names clickable present in the frontend. How can I accomplish this

    Best regards
    Jan Hoppe Winther Nielsen

    1. Hi Jan,

      Good question! 🙂

      There is an example on the dynamic hyperlink page, but I see now there are two versions of this page. Sorry for the confusion! I removed the content of the older version which you were replying to and moved all the comments to the newer version. Hope you’ll find the new page!

      If you scroll up, you’ll find an if-then-else macro example which contains the code you are looking for:
      $$name$$

      Please be aware that your dynamic hyperlink will be added as a new column. To use the dynamic hyperlink instead of the hyperlink column, remove the hyperlink column from your publication or project and add the dynamic hyperlink column.

      Hope this helps,
      Peter

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × 2 =