Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Detect If On A Single Post / Page on Tumblr?

I haven't found a way to detect if user is currently viewing a page, post or an entire list of articles. WordPress has functions like is_page, is_single, etc for that, but does anyone have a way for Tumblr? I'm currently 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'm wondering if that is the best way of doing this or is there an alternative?

like image 447
Asko Nõmm Avatar asked Nov 27 '22 09:11

Asko Nõmm


1 Answers

I've found a more adequate solution. According to Tumblr's documentation:

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

{block:PermalinkPage} {/block:PermalinkPage} Rendered on post permalink pages.

So basically, code wrapped in the IndexPage block will run only on pages that can display more then one post whether it's a text, photo, video, etc post.

...and code wrapped in the PermalinkPage will only run for single post permalink pages.

like image 103
EasyCo Avatar answered Dec 07 '22 22:12

EasyCo