Can You Use PHP in A Tumblr Theme? [closed]

一笑奈何 提交于 2019-12-11 03:21:11

问题


I want to use a PHP variable within a tumblr theme so that photo sizes are random. Is it possible to use PHP within a tumblr custom theme or is it its own language/API that doesn't allow PHP inline?


回答1:


No because it will cause security vulnerabilities and that is the reason why they are using mustache in their themes. I'm also quite sure that tumblr isn't written in PHP.




回答2:


I did some more research and I think this method using tags is maybe the best, at least the most user friendly:

Can you customize the format of a Tumblr post based on its tag?

I set a few different classes in the CSS for my clients, .small, .medium, .large. Now they can just tag with any of those three words and the photo will be resized accordingly. The only drawback is that the tags are visible within tumblr's photo stream so you might see "#small" or something like that. I'd rather not have this but I can't really think of an easier way for the user to easily add a class to a post.




回答3:


You can not use PHP variables in Tumblr themes, because Tumblr using their own templating engine instead of PHP.

Only one real variables variable you can create with Tumblr themes are Theme appearance options, but they are common for all theme.

You have several possible solution:

  • Use Tumblr API on your own project with PHP.
  • Use “Create a custom HTML theme” guide for creating customizations classes (with css) per post, like I'm doing in my developed Hampi theme:

    <article id="post{PostID}" class="
        {PostType}
        {block:PostNotes}hasnotes{block:PostNotes}
        {block:More}hasmore{/block:More}
        {block:HasTags}hastags{/block:HasTags}
        {block:Date}
            postdate-{AmPm}
            postdate-{ShortDayOfWeek}
            postdate-{ShortMonth}
            postdate-{DayOfMonthWithZero}
            postdate-{Year}
        {/block:Date}
        {TagsAsClasses}
    ">
    
  • Use javascript (jQuery, actually) for modifying styles for each post with random values of width, like in this demo on jsFiddle:

    $(function() {
        $.each($('.post'), function(i, post) {
            var max = 800,
                min = 500,
                rand = (Math.floor(Math.random() * max) + min);
    
            $(post).css('width', rand);
        });
    });​
    

    With this result for max=200 and min=100:



来源:https://stackoverflow.com/questions/11109428/can-you-use-php-in-a-tumblr-theme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!