RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.38% (6.14%*) • Home Loan Fixed: 5.44% (6.26%*) • Fixed: 5.44% (6.26%*) • Variable: 5.38% (6.14%*) • Investment IO: 5.69% (6.52%*) • Investment PI: 5.49% (5.98%*)

Add Australia’s Current Population To Your Website

Add Australia’s Current Population To Your Website

As part of our efforts to provide additional services on our soon-to-be revised Australian Security Journal, we're building a number of APIs that support the information we'd like to generally share and use. One of those APIs deals with Australian Road Fatalities. Since we'd like to provide a reference to the impact of the fatality count over time (say, per 100,000 population), we needed a source of historical population data from which to calculate those numbers. In playing with data from the Australian Bureau of Statistics we stumbled across a funky little tool that provides incremental real-time population growth based on predictive data. The following article will show you how to include that data on your website.

The following shortcode will return data almost exactly as the ABS has done on its website. The shortcode of [bmauspop] returns the following:

0

This projection is based on the estimated resident population at and assumes growth since then of:

  • One birth every .
  • One death every .
  • A net gain of one international migration every .
  • An overall total population increase of one person every .
  • These assumptions are consistent with figures released in

    We're caching data for 18 hours.

    WordPress Shortcode

    Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

    Usage requires the Simple Cache plugin. This simply makes life easier by retrieving older data is the transient has expired and the API is unresponsive.

    1
    <?php 
    2
    /*
    3
     Add Australia's Current Population To Your Website
    4
     https://www.beliefmedia.com.au/australia-population
    5
    */
    6
     
    7
    8
     
    9
      $atts = shortcode_atts(array(
    10
        'meta' => 1,
    11
        'style' => 'font-size: 2.0em; color: #008000; text-align: center; text-decoration: bold;',
    12
        'cache' => 3600 * 18
    13
      ), $atts);
    14
     
    15
      $transient = 'bmaupp_' . md5(serialize($atts));
    16
      $cached =  beliefmedia_get_transient($transient, $atts['cache']);
    17
     
    18
      if ($cached !== false ) {
    19
        return $cached;
    20
     
    21
      } else {
    22
     
    23
      /* Get current data */
    24
      $data = @file_get_contents('http://www.abs.gov.au/api/demography/populationprojection');
    25
      if ($data === false) return beliefmedia_get_transient_data($transient);
    26
      $data = json_decode($data, true);
    27
     
    28
      /* Primary population */
    29
      $return = '
    30
    <p style="' . $atts['style'] . '">' . number_format($data['popNow']) . '';
    31
     
    32
      if ($atts['meta']) {
    33
     
    34
        $return .='This projection is based on the estimated resident population at <strong>' . $data['rojectionStartDate'] . '</strong> and assumes growth since then of:';
    35
        $return .= '
    36
    <ul>
    37
    <li>One birth every ' . $data['birthRate'] . '.</li>
    38
    <li>One death every ' . $data['deathRate'] . '.</li>
    39
    <li>A net gain of one international migration every ' . $data['overseasMigrationRate'] . '.</li>
    40
    <li>An overall total population increase of one person every ' . $data['growthRate'] . '.</li>
    41
     
    42
    ';
    43
        $return .= 'These assumptions are consistent with figures released in ' . $data['source'] . '';
    44
     
    45
      }
    46
     
    47
      /* Cache result */
    48
      beliefmedia_set_transient($transient, $return);
    49
     
    50
      return $return;
    51
     }
    52
    }
    53
    add_shortcode('bmauspop', 'beliefmedia_australia_abs_population');

    If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

    Shortcode Attributes

    The following shortcode attributes are available.

    meta

    Using meta="1" will show the bullet list of data underneath the population (default). To disable, use meta="0" in your shortcode or hardcode it into the shortcode function. The resulting population figure without meta data is shown below.

    0

    style

    The style is applied to the population figure only. By default we use font-size: 2.0em; color: #008000; text-align: center; text-decoration: bold;.

    cache

    We cache data for 18 hours by default only because we have no need to provide accurate numbers. Alter as required.

    PHP Function

    Used outside of WordPress, the following may be used. Usage of Simple Cache is required (to avoid making repeated requests to the ABS API).

    1
    <?php 
    2
    include('simple-cache/cache.inc.php');
    3
     
    4
    /*
    5
     Add Australia's Current Population To Your Website
    6
     https://www.beliefmedia.com.au/australia-population
    7
    */
    8
     
    9
    function beliefmedia_australia_population($cache = '86400') {
    10
     
    11
      /* Transient and get JSON data */
    12
      $transient = 'oz_population_' . md5(serialize(func_get_args));
    13
     
    14
      $cached =  beliefmedia_get_transient($transient, $cache);
    15
      if ($cached !== false) return $cached;
    16
     
    17
      $data = @file_get_contents('http://www.abs.gov.au/api/demography/populationprojection');
    18
      if ($data === false) return beliefmedia_get_transient_data($transient);
    19
     
    20
      $data = json_decode($data, true);
    21
     
    22
      /* Simple result only */
    23
      $return = '
    24
    <p style="font-size: 2.0em; color: #008000; text-align: center; text-decoration: bold;">' . number_format($data['popNow']) . '';
    25
     
    26
      /* Cache result */
    27
      beliefmedia_set_transient($transient, $return);
    28
     
    29
     return $return;
    30
    }
    31
     
    32
    /* Usage */
    33
    echo beliefmedia_australia_population();

    Considerations

    • The ABS JSON data unfolds as follows. Use as required:
    1
    Array
    2
    (
    3
        [attribution] => Australian Bureau of Statistics
    4
        [popNow] => 24844714
    5
        [timeStamp] => 01 Mar 2018 13:06:47 AEDT
    6
        [projectionStartDate] => 30 June 2017
    7
        [birthRate] => 1 minute and 44 seconds
    8
        [deathRate] => 3 minutes and 17 seconds
    9
        [overseasMigrationRate] => 2 minutes and 20 seconds
    10
        [growthRate] => 1 minute and 25 seconds
    11
        [rateSecond] => 85.59958524807756512392
    12
        [source] => Australian Demographic Statistics, June Quarter 2017 (cat. no. 3101.0)
    13
        [sourceURL] => http://www.abs.gov.au/ausstats/abs@.nsf/mf/3101.0
    14
        [copyRight] => Copyright Commonwealth of Australia
    15
    )
    • The data is copyright of the ABS and appropriate attribution should be provided.
    • Given the growth rate is provided, you might consider providing projections. Additionally, you might store current data in a cookie or session and then provide growth since a last visit etc.
    • There's a lot of data on the ABS website... some that we'll return to over time. In particular, we'll be sourcing finance data for our clients and will incorporate relevant code into the BM Finance Plugin.

    Download


    Title: Add Australia's Current Population To Your Website (WP Shortcode)
    Description: Add Australia's Current Population To Your Website. Sourced from ABS.
      Download • Version 0.1, 989.0B, zip, Category: WordPress Shortcodes
    PHP Code & Snippets, (697.0B)    

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment