How to detect if on one page / page on Tumblr?

I did not find a way to determine if the user is viewing a page, message, or the entire list of articles. WordPress has features like is_page, is_single, etc., but does anyone have a way for Tumblr? I am now hacking it with the following code:

$(function() { var uri_root = 'http://' + window.location.hostname + '/'; var uri = window.location.href; if(uri_root !== uri){ alert("Viewing a single POST or PAGE!"); } }); 

I am wondering if this is the best way to do this or is there an alternative?

+4
source share
3 answers

Each message has a class separator. So, count the number of divs with post classes.

Something like this: $('div.post').length or document.getElementsByClassName('post') if jQuery is missing.

0
source

I found a more adequate solution. According to the Tumblr documentation:

{block: IndexPage} {/ block: IndexPage} Displayed on index pages (post).

{block: PermalinkPage} {/ block: PermalinkPage} Displayed on pages with a constant position.

Thus, the code enclosed in the IndexPage block only runs on pages that can display more than one message, be it text, photo, video, etc.

... and the code enclosed in PermalinkPage will only work for pages with a constant position.

+30
source

To determine if this is on the page or post page , I created this script that worked fine for me.

 {block:PermalinkPage} var page = {JSPostID}; if(page == '') alert('Page!'); else alert('Post'); {/block:PermalinkPage} 

Or use the simplest functions

 function isPage(){ {block:PermalinkPage} if({JSPostID} == '') return true; {/block:PermalinkPage} return false; } function isPost(){ {block:PermalinkPage} if({JSPostID} != '') return true; {/block:PermalinkPage} return false; } 
0
source

Source: https://habr.com/ru/post/1395263/


All Articles