Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In tumblr, show only posts with a certain tag in the home page

Tags:

tumblr

In tumblr, is it possible to show only posts with a certain tag in the home page?
If so, how is it done?

like image 447
Damian Avatar asked Jun 30 '13 20:06

Damian


3 Answers

I just wrote up the solution to the opposite problem here:

  • How to hide the posts with a given tag from the homepage.

You can take inspiration from there and implement the opposite. Alternatively, you can simply add a "hidden" tag to each one of the things that you don't want displayed on the homepage.

like image 136
mircealungu Avatar answered Sep 20 '22 15:09

mircealungu


I know that this topic is quite old, but I figured I'd share what I did for anyone who is still looking for an answer to this problem.

First, paste the following code after the "</title>" in your theme HTML.

<meta name="text:Default Tag" content="" />

Next, right after the "<body>" in your theme's HTML, paste the following:

{block:IndexPage}<script type="text/javascript">
    var url = location.href;
    if (url == "{BlogURL}") {
        window.location = "{BlogURL}tagged/{text:Default Tag}";
    }
</script>{/block:IndexPage}

In your theme settings, you should see a box labeled "Default Tag". Put the tag you'd like posts to appear for in that box (without a hashtag) and click save.

Now, if someone visits your blog, it will forward them to the page that shows posts with your specified tag. Of course, this probably isn't the best way of doing it, but it's the best way I could come up with that wouldn't mess up themes.

Another thing I like about this way of doing this, is that you can send someone your blog URL with a "/?" appended to it (e.g. "myblog.tumblr.com/?") and it will show all of your posts.

like image 45
Preston159 Avatar answered Sep 19 '22 15:09

Preston159


Using mircealungu's suggestion worked perfectly for me! Here's how I did it:

1. Find the article tag, and add the classname:

class="notfeatured {TagsAsClasses}"

If it already has a classname, add the part in bold above inside the classname quotes. Mine ended up looking like this:

<article id="{PostID}" class="post notfeatured {TagsAsClasses} {PostType}{block:PermalinkPage} {block:Date}not-{/block:Date}page{/block:PermalinkPage}">

2. Find the div tag that precedes the article tag, and add the classname:

class="{block:TagPage} tag_page {/block:TagPage}{block:PermalinkPage}perma_page{/block:PermalinkPage}"

Again, if a class already exists, just add the part in bold above inside the classname quotes. Mine ended up like this:

<div id="posts" class="{block:TagPage} tag_page {/block:TagPage}{block:PermalinkPage}perma_page{/block:PermalinkPage}" >

3. Finally, add this to your CSS:

article.notfeatured {display: none;}
article.featured, .tag_page article.notfeatured, .perma_page article.notfeatured {display: block;}

Now any post tagged as "featured" will display on your home page, but nothing else. So far no issues for me, it works great! You can see it here.

You can also use javascript to reorder the display so you can make the featured posts appear first in a list. The script is very simple:

$('article.featured').prependTo('#posts');

And here is a demo. Just place that inside javascript tags and put it right before the /body tag in your theme. In this case don't use the CSS above, because you don't want to hide the posts. I implemented a .top class for the script and kept the .featured class for the CSS, and I use both the CSS and the script.

like image 40
user3518948 Avatar answered Sep 16 '22 15:09

user3518948