{"id":53975,"date":"2021-11-19T03:01:20","date_gmt":"2021-11-18T17:01:20","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=53975"},"modified":"2021-11-19T11:27:28","modified_gmt":"2021-11-19T01:27:28","slug":"hashtag-navigation-scrolling-tweaks-wordpress-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/hashtag-navigation-scrolling-tweaks-wordpress-tutorial\/","title":{"rendered":"Hashtag Navigation Scrolling Tweaks WordPress Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/ITblog\/\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Hashtag Navigation Scrolling Tweaks WordPress Tutorial\" src=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/hashtag_and_a_bit_wp.gif\" title=\"Hashtag Navigation Scrolling Tweaks WordPress Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Hashtag Navigation Scrolling Tweaks WordPress Tutorial<\/p><\/div>\n<p>The recent <a title='Hashtag Navigation Scrolling Tweaks Primer Tutorial' href='#hnstpt'>Hashtag Navigation Scrolling Tweaks Primer Tutorial<\/a> &#8220;proof of concept&#8221; ideas gave us something to work on to fix some annoyances with navigation to this WordPress Blog you are reading.  We found that we often fell short of the hashtag navigation we wanted to achieve<font size=1>, a little selfishly, <\/font>because the &#8220;admin user&#8221; toolbar took up enough height to put out the hashtag navigation.<\/p>\n<p>In order to remedy the fault<font size=1>, albeit a little selfishly, <\/font>we changed this WordPress Blog&#8217;s Twenty Ten theme&#8217;s <font size=1>good ol&#8217;<\/font> header.php as below &#8230;<\/p>\n<ol>\n<li>we added in a script link to the new external Javascript as per &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n&lt;script type='text\/javascript' src='\/\/www.rjmprogramming.com.au\/hashtag_and_a_bit.js'&gt;&lt;\/script&gt;<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<li>fix those calls to the RJM Programming <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/ITblog\/\">WordPress Blog<\/a> from the dropdown of the RJM Programming <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\">Landing Page<\/a> <font color=blue>we append<\/font> &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\nfunction post_pp_ref() {<br \/>\n  if (document.getElementById('iftable')) {<br \/>\n    location.href='#iftable<font color=blue>#andabit=-60<\/font>';<br \/>\n  }<br \/>\n}<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<li>fix the mobile platform calls to the WordPress Blog that often hashtag straight to the relevant posting&#8217;s content ( via #content ) &#8230; it&#8217;s fixed via code in that external Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/hashtag_and_a_bit.js_GETME\">hashtag_and_a_bit.js<\/a> <font color=blue>(and an added if clause)<\/font> &#8230;<br \/>\n<code><br \/>\n\/\/ hashtag_and_a_bit.js<br \/>\n\/\/ RJM Programming<br \/>\n\/\/ November, 2021<br \/>\n\/\/ Help out Hashtag Position Less a Bit<br \/>\n<br \/>\n  var firstlfh='';<br \/>\n  var dgbiv='-40';<br \/>\n<br \/>\n  function lfh() {<br \/>\n    if (1 == 1) {<br \/>\n    var thish=('' + location.hash);<br \/>\n    if (thish != firstlfh) {<br \/>\n      firstlfh=thish;<br \/>\n      if (firstlfh.split('#').length &gt; 2) {<br \/>\n        if (firstlfh.split('#andabit').length == 2) {<br \/>\n          window.scroll(0, 0);<br \/>\n          var rect=document.getElementById(firstlfh.split('#')[1].split('#')[0]).<a target=_blank title='Javascript DOM getBoundingClientRect information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/met_element_getboundingclientrect.asp'>getBoundingClientRect<\/a>();<br \/>\n          if (('' + rect.top) != '') {<br \/>\n            var newtop=eval(('' + rect.y)); \/\/y));<br \/>\n            newtop+=eval('' + dgbiv); \/\/document.getElementById('i1').value);<br \/>\n            window.scroll(0, newtop);<br \/>\n          }<br \/>\n        }<br \/>\n      <font color=blue>} else if (thish.indexOf('#content') != -1) {<br \/>\n         window.scroll(0, 0);<br \/>\n          var rect=document.getElementById(thish.split('#')[1].split('#')[0]).getBoundingClientRect();<br \/>\n          if (('' + rect.top) != '') {<br \/>\n            console.log('rect.y=' + rect.y);<br \/>\n            var newtopc=eval(('' + rect.y)); \/\/y));<br \/>\n            newtopc-=eval('30'); \/\/document.getElementById('i1').value);<br \/>\n            console.log('newtopc=' + newtopc);<br \/>\n            window.scroll(0, newtopc);<br \/>\n          }<\/font><br \/>\n      }<br \/>\n    }<br \/>\n    }<br \/>\n  }<br \/>\n<br \/>\n  setInterval(lfh, 1000);<br \/>\n<\/code>\n<\/li>\n<\/ol>\n<p> &#8230; to make life better administering this blog.  Perhaps with you too?!  We certainly hope so!<\/p>\n<p><b><i>Did you know?<\/i><\/b><\/p>\n<p>Yes &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\n&lt;script type='text\/javascript' src='\/\/www.rjmprogramming.com.au\/hashtag_and_a_bit.js'&gt;&lt;\/script&gt;<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<p> &#8230; could <i>more generically<\/i> be &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\n&lt;script type='text\/javascript' src='\/hashtag_and_a_bit.js'&gt;&lt;\/script&gt;<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<p> &#8230; as a kind of &#8220;hybrid&#8221; relative URL (that is a bit like an absolute URL in that if you know you are dealing with the RJM Programming domain, you are pointing at its <a target=_blank title='Apache web server' href='https:\/\/httpd.apache.org\/'>Apache<\/a> (with PHP) web server <a target=_blank title='PHP $_SERVER info' href='https:\/\/www.php.net\/manual\/en\/reserved.variables.server.php'>$_SERVER[&#8216;DOCUMENT_ROOT&#8217;]<\/a> folder&#8217;s hashtag_and_a_bit.js external Javascript).  Equally, without code modification, the latter syntax could suit a local Apache (we like <a target=_blank title='MAMP' href='https:\/\/mamp.info'>MAMP<\/a>) web server environment, as the place for hashtag_and_a_bit.js external Javascript, also placed into that local Apache (we like <a target=_blank title='MAMP' href='https:\/\/mamp.info'>MAMP<\/a>) web server environment&#8217;s $_SERVER[&#8216;DOCUMENT_ROOT&#8217;] folder (here on macOS on a MacBook Air with <a target=_blank title='MAMP' href='https:\/\/mamp.info'>MAMP<\/a> that is <i>\/Applications\/MAMP\/htdocs\/<\/i> or <i>HTTP:\/\/localhost:8888\/<\/i> as the &#8220;URL part&#8221; equivalence).<\/p>\n<p>And then, do you get, seeing &#8230;<\/p>\n<p><code><br \/>\nlocation.href='#iftable#andabit=-60';<br \/>\n<\/code><\/p>\n<p> &#8230; how hashtag (ie. location.hash) coding could take advantage of the fact that location.hash could be parsed via Javascript &#8230;<\/p>\n<p><code><br \/>\n  var bitsofhashare=('' + location.hash + String.fromCharCode(32)).substring(1).trim().split('#');<br \/>\n<\/code><\/p>\n<p> &#8230; to arrive at, for case above <i>bitsofhashare[0]=&#8221;iftable&#8221;;<\/i> and <i>bitsofhashare[1]=&#8221;andabit=-60&#8243;;<\/i> and <i>bitsofhashare[0]=&#8221;&#8221;;<\/i> for the case where there is no defined location.hash ?<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/hashtag-navigation-scrolling-tweaks-wordpress-tutorial\/'>Hashtag Navigation Scrolling Tweaks WordPress Tutorial<\/a>.<\/p-->\n<hr>\n<p id='hnstpt'>Previous relevant <a target=_blank title='Hashtag Navigation Scrolling Tweaks Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/hashtag-navigation-scrolling-tweaks-primer-tutorial\/'>Hashtag Navigation Scrolling Tweaks Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/hashtag_and_a_bit.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Hashtag Navigation Scrolling Tweaks Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/hashtag_and_a_bit_poc.jpg\" title=\"Hashtag Navigation Scrolling Tweaks Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Hashtag Navigation Scrolling Tweaks Primer Tutorial<\/p><\/div>\n<p>We&#8217;ve got what we hope is an interesting proof of concept web application for you today.  What do you think of &#8230;<\/p>\n<blockquote><p>\nHagtag navigation plus a Scrolling correction\n<\/p><\/blockquote>\n<p> &#8230; combining that &#8230;<\/p>\n<ul>\n<li>HTML #hashtag navigation eg. #t5  &#8230; combined with &#8230;<\/li>\n<li>Javascript location.hash detection of this plus any &#8220;double hashtagging&#8221; eg. #t5#andabit=-40  &#8230; combined with &#8230;<\/li>\n<li>Javascript document.getElementById(&#8216;t5&#8217;).getBoundingClientRect().y usage within (external Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/hashtag_and_a_bit.js_GETME\" title=\"hashtag_and_a_bit.js\">hashtag_and_a_bit.js<\/a>) &#8230;<br \/>\n<code><br \/>\n\/\/ hashtag_and_a_bit.js<br \/>\n\/\/ RJM Programming<br \/>\n\/\/ November, 2021<br \/>\n\/\/ Help out Hashtag Position Less a Bit<br \/>\n<br \/>\n  var firstlfh='';<br \/>\n  var dgbiv='-40';<br \/>\n<br \/> <br \/>\n  function lfh() {<br \/>\n    if (1 == 1) {<br \/>\n    var thish=('' + location.hash);<br \/>\n    if (thish != firstlfh) {<br \/>\n      firstlfh=thish;<br \/>\n      if (firstlfh.split('#').length &gt; 2) {<br \/>\n        if (firstlfh.split('#andabit').length == 2) {<br \/>\n          window.scroll(0, 0);<br \/>\n          var rect=document.getElementById(firstlfh.split('#')[1].split('#')[0]).getBoundingClientRect();<br \/>\n          if (('' + rect.top) != '') {<br \/>\n            var newtop=eval(('' + rect.y));<br \/>\n            newtop+=eval('' + dgbiv); \/\/document.getElementById('i1').value);<br \/>\n            window.scroll(0, newtop);<br \/>\n          }<br \/>\n        }<br \/>\n      }<br \/>\n    }<br \/>\n    }<br \/>\n  }<br \/>\n<br \/>\n  setInterval(lfh, 1000);<br \/>\n<\/code>\n<\/li>\n<\/ul>\n<p> &#8230; to cover for those occasions where hashtag navigation misses the &#8220;true&#8221; mark you intended, as it is apt to do, in our experience?  And in our experience a &#8220;small scrolling correction&#8221; can hit the &#8220;true&#8221; mark, it&#8217;s just that with today&#8217;s proof of concept <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/hashtag_and_a_bit.html_GETME\" title=\"hashtag_and_a_bit.html\">hashtag_and_a_bit.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/hashtag_and_a_bit.html\" title=\"Click picture\">web application<\/a> it can be programmed for rather that being a second step occasionally requiring user intervention &#8230;<\/p>\n<div class=\"container demo animated\"><iframe style='width:100%;height:400px;' src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/hashtag_and_a_bit.html\"><\/iframe><\/div>\n<p> &#8230; for those users who hate &#8220;tweak scrolling&#8221;, we guess!<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d53931' onclick='var dv=document.getElementById(\"d53931\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/hashtag\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d53931' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d53975' onclick='var dv=document.getElementById(\"d53975\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/getBoundingClientRect\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d53975' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The recent Hashtag Navigation Scrolling Tweaks Primer Tutorial &#8220;proof of concept&#8221; ideas gave us something to work on to fix some annoyances with navigation to this WordPress Blog you are reading. We found that we often fell short of the &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/hashtag-navigation-scrolling-tweaks-wordpress-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[3860,3418,61,85,151,327,409,2208,2229,557,652,680,830,932,3859,1456,3276],"class_list":["post-53975","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-_serverdocument_root","tag-admin","tag-administration","tag-apache","tag-blog","tag-did-you-know","tag-external-javascript","tag-getboundingclientrect","tag-hash","tag-hashtag","tag-javascript","tag-landing-page","tag-navigation","tag-php","tag-twentyten-twenty-ten-theme","tag-wordpress","tag-wordpress-blog"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/53975"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=53975"}],"version-history":[{"count":16,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/53975\/revisions"}],"predecessor-version":[{"id":54012,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/53975\/revisions\/54012"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=53975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=53975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=53975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}