• Resolved pierre1688

    (@pierre1688)


    Dear all,
    Sorry for my poor English in advance!
    As this subject, I wanna change another URL’s structure. I tried below code in Additional JavaScript field. But it still can’t recover properly. It means share count is zero. Is there any comment to resolve it? Please advice! Thanks a million.

    <PS> For instance:
    The original post website format is “https://test.idv.tw/2018/01/02/content/
    Now, changed to “https://test.idv.tw/content/. Crossed out “2018/01/02”.

    <script>
    var a2a_config = a2a_config || {};
    a2a_config.counts = {
    // Recover old URL structure

    recover: function(data) {
    var kitData = data.kit.dataset;
    if (kitData && kitData.year && kitData.month && kitData.day) {

    return ‘https://test.idv.tw/&#8217;
    + kitData.year + ‘/’
    + kitData.month + ‘/’
    + kitData.day + ‘/’
    + data.pathParts[data.pathParts.length – 1] + ‘/’;
    }
    }

    };
    </script>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author micropat

    (@micropat)

    You will need to make the date data available in your theme’s HTML code; something like:

    <body data-year="2020" data-month="01" data-day="21">

    Then your Share Count Recovery code will be something like:

    a2a_config.counts = {
        // Recover old URL structure
        recover: function(data) {
            var bodyData = document.body.dataset;
            // If the <body> tag has "data-" attributes in the HTML like:
            // <body data-year="2020" data-month="01" data-day="20">
            if (bodyData && bodyData.year && bodyData.month && bodyData.day) {
                // Arrange the pathname parts of the old URL like:
                // https://www.example.com/2020/01/20/post-name/
                return 'https://www.example.com/'
                    + bodyData.year + '/' 
                    + bodyData.month + '/' 
                    + bodyData.day + '/' 
                    + data.pathParts[data.pathParts.length - 1] + '/';
            }
        }
    };
    Thread Starter pierre1688

    (@pierre1688)

    Dear Micropat,
    Thanks for replying this mail.
    I am new for WordPress environment with my website. So I don’t have any ideas to add it into my theme’s HTML code.
    And what difference are they with [document.body.dataset] and [data.kit.dataset]?
    And what does it mean with below line?
    var a2a_config = a2a_config || {};
    Because it seems not to appear in your suggestion code.

    Will you help me again for those basic knowledge technology for this question?
    Thanks again!

    Thread Starter pierre1688

    (@pierre1688)

    Dear Micropat,
    Sorry for any inconvenience again!
    I am still researching this. So far, I tried below way to resolve this issue. Unfortunately, it failed. This was I experimented.

    Step1: Added “custom field” into the post with Key/Value.
    Step2: Added three sets of K/V,

    For example:
    Key:data-year Value:2017 / Key:data-month Value:10 / Key:data-day Value:20

    Could please you give me any directions to resolve it? And I still can’t understand what meaning with [document.body.dataset] this line?
    Can you share any document or linking to understand below code true meaning?
    Please advise! Thanks a million.

    code:
    a2a_config.counts = {
    // Recover old URL structure

    recover: function(data) {
    var kitData = document.body.dataset;
    // If the AddToAny instance has “data-” attributes in the HTML like:
    // <div class=”a2a_kit” data-year=”2020″ data-month=”01″ data-post-id=”123″>
    if (kitData && kitData.year && kitData.month && kitData.day) {
    // Arrange the pathname parts of the old URL like:
    // http://old.example.com/2020/01/123/post-name/
    return ‘https://test.idv.tw/&#8217;
    + kitData.year + ‘/’
    + kitData.month + ‘/’
     + kitData.day + ‘/’
    + data.pathParts[data.pathParts.length – 1] + ‘/’;
    }
    }

    };

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can’t recover share count with another URL structure’ is closed to new replies.