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

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

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.

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.

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.

Tumblr’s Custom Themes don’t provide such a functionality.
You could use JS or CSS to (visually) hide all posts without a specific tag on the index page, but that way you won’t have the full 10 (or whatever you configured) posts per page anymore.
You could probably use Tumblr’s API to create a list of matching posts (with Javascript) and display that content instead of the default posts (so your custom theme would only contain the script for the index page content). You would have to make sure that the pager still works, though.

Actually, it is possible, but it might not work how you want.
1st. Identify the id of your individual posts (usually something like #post or #entry, lets call yours #entry)
2nd. Replace your opening post div with this:
2nd. Add this bit of css
{block:IndexPage}
#entry (or whatever name it is) {display:none}
.featured {display:inline !important}
{/block:IndexPAge}
3rd. Tag all the posts you want to show on your homepage without quotes as "featured"
This should work, but it will most likely hide all the non "featured" posts on your search page and tag page as well, which you may not want.
If you want your users to be directed to a specific 'splashpage' when they visit your blog, you could always use a jquery redirect script. Hope some of this helped!

Im sorry to say, with their existing theme options as of today, you cannot achieve this without horribly ruining your seo reputation.

I have tried many ways to do this, using tumblr php api and other,
This worked for me: I am using a page outside tumblr and loading the tagged posts via curl php calls.
It can be done via ajax but for SEO reasons I wanted to use php.
Here is the code:
$oath = 'xxx';
$blogName = 'yyy.tumblr.com';
$tag='tagname';
$apiLink = "http://api.tumblr.com/v2/blog/$blogName/posts/?api_key=$oath&tag=$tag";
// Initializing curl
$ch = curl_init( $apiLink );
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
);
// Setting curl options
curl_setopt_array( $ch, $options );
// Getting results
$result = curl_exec($ch); // Getting JSON result string
$data = json_decode($result);
$posts = $data->response->posts;

I realise this is old, but I've just had to do it, so here is my solution. At the end of the theme, in the script tags add:
{block:IndexPage}
$( ".the-posts" ).load( "tagged/home .the-posts article" );
{/block:IndexPage}
Where home is the tag you have given the posts you wish to see on the index page. This will basically load the correct articles into the posts div, replacing what it there. See the jquery man page: http://api.jquery.com/load/ for more info.

Related

Creating a Tumblr Landing Page Using Redirect Code

there was a similar question to this one asked a while back - but for some reason the comment that contained specific instructions for the workaround was deleted.
I am attempting to create a landing page on a tumblr page using the redirect code below.
<script type="text/javascript">
if(location.href == 'http://labellablog.com/') location.replace('http://labellablog.com/welcome');;
</script>
The issue that I'm experiencing is the same as the person who posted the question in the first place - by putting the redirect code in the index page, it creates a loop. i.e. In trying to click the link on the 'welcome page' in order to get to the home page containing blog posts, navigation etc., it simply re-directs to the 'welcome' page.
The solution that is mentioned (not in great detail) on another question states that you must set the cookies to expire in a certain amount of time. Unfortunately I'm a huge amateur when it comes to coding and am not entirely sure how to achieve this.
Thanks in advance for any advice.
Method 1
Based on your question this is how I would resolve it (this is not using the cookie method at all, but I will come to that).
Make sure jquery is installed in your theme, alot of themes already have it, if not you can add it to the head of the document like so:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Lets look for the index page:
var primaryDir = document.location.pathname.split("/")[1]; // get the first directory
if (!primaryDir){ // if the primary directory is empty (index page) lets redirect to another page
window.location('/welcome');
}
You can use /welcome and that will work if you change the name/url of your site/tumblr.
So this method means this will always run (unless you disable javascript) for every client that connects to your site. This means effectively that the index page is never visible.
Now if you wanted a cookie method, this would mean that you would create the redirect on the first visit, then set the cookie and then after that the index page would be visible.
If that is what you want, let me know, but that involves quite a bit more code, slightly more complex solution.
EDIT
Another way to achieve this is to create a hidden div in the main template that only shows on the index page and is hidden on all other pages, this means you don't have to rely on a slightly slower redirect.
I only posted an answer to that issue the other day: How can I make a Tumblr background image only for one page?
Method 2
OK here is a method adopting cookies.
First I recommend downloading this jquery cookie plugin
You will then need to link to that as a resource in your theme, so you need somewhere to host that file. I use dropbox, but tumblr also has a repository for linking to files (well it used to seems to have disappeared).
Now create an element that will sit over the main page:
Enter
You can style this to fill the whole page if required (modify to your needs):
#entry {
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
background:#CCC;
color:#FFF;
// yadda yadda
}
Now we need some click event to create the cookie when we click on this huge anchor:
$(document).ready(function(){
var entry = $('#entry'); // lets cache the selector in a variable
entry.on('click',function(){
$.cookie('deadlyrhythm', '1', { path: '/', expires: 1}); // set a cookie with the name deadlyrhythm to the value of 1 on the entire site for 1 day.
$(this).hide();
return false;
});
});
Now we need a method to check if the cookie exists, so inside the same document ready function:
if ($.cookie('deadlyrhythm') != '1'){
entry.hide();
}
This should mean that for 24 hours the cookie is set and the entry will not display if the same user revists the site, but it will after one day, of course you can set that value to anything you like.
As I mentioned this is slightly more complex to implement, but in the console of the browser you can check to see if a cookie exists and delete it manually (I use chrome for this) this is really useful for testing.

How can we make comments and likes ignore the #anchor from URLs so one whole page only has one set of comments and likes?

I always find concrete examples help the most... so here's an example URL:
http://www.humanreligions.info/humanism.html
The comments and like button work as expected. But if I user has clicked on this link to get the the page, or if they click on one of the menu items and then happen to refresh the page, the browser URL is:
http://www.humanreligions.info/humanism.html#Organisations
and none of the likes and comments from the base page show up. Because of the anchor, FB is treating it as a whole new page, which is not what an anchor means nor what I want it to do.
Questions/answers on this (I've been searching for a while, sure that others must have stumbled across this simple bug!) all seem to be where people do want the # to mean something special. This was asked a year ago here facebook comment count url with an '#' anchor tag? but there are no answers,
Here are relevent code snippets from the page:
LIKE BUTTON CODE (simplified):
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.humanreligions.info%2Fhumanism.html"></iframe>
COMMENTS:
<div id="fb-root"></div><fb:comments href="http://www.humanreligions.info/humanism.html"></fb:comments>
MISC:
<meta property="og:url" content="http://www.humanreligions.info/humanism.html">
What else does it require to make FB treat one page as one page regardless of (irrevelent) internal anchors?
I know that I'm really late with this, but you can add a the data-href attribute to the facebook like button when you are using the XMLNS version of it, which I can see is being used from the comments section. So for your example you would put:
<fb:like layout="box_count" action="like" show_faces="true" share="true" data-href="http://www.humanreligions.info/humanism.html"></fb:like>

Facebook feed link back to article not working for Facebook Comments implemented on custom CMS

I implemented facebook comments across a legacy, custom CMS. I used the XFBML implementation. Everything works as expected except when clicking the links back to the article page from a commenter's facebook feed the comment box does not show any comments. The link is of this form:
{Article URL}?fb_comment_id={comment_id_string}
And if I remove the comment parameter and only go to the article url the comment box renders correctly with the comment and all other comments on the article. So, it's some issue with the fb_comment_id parameter. One weird thing about how I had to implement the comments is, because of how the routing on the site works, I could not use server side code to set the the URL parameter in the <fb:comments> object. So I had to use this jquery code in the <head>:
<script>
// assign current page to comments url
$(document).ready(function() {
$('fb\\:comments').each(function(){
$(this).attr('href', window.location);
});
});
</script>
And used this for the actual <fb:comments> code:
<fb:comments href="{site's root URL}" num_posts="8" width="570"></fb:comments>
So, I figure doing this client side may be causing the issue. Not doing this server side is a hard constraint though, and everything else works so I'm hopeful there may be some way to make this work. If making the comment link work correctly is impossible, a reasonable hack would be to rewrite the link in the facebook feed so that it just points to the article url without adding the comment parameter. Any suggestions? Thanks!
NOTE: I've also tried using the html5 comments implementation and there is the same issue.;
Once facebook has rendered the iframe based upon your fb:comments tag, does it have the correct url? I am thinking it does not. You may have to call FB.XFBML.parse() after you inject the complete

Like Box - Showing "check in's" rather than recent posts?

I just added a Facebook Like Box, per the instructions on the developers page here:https://developers.facebook.com/docs/reference/plugins/like-box/
The page says it should show recent posts from the page. However, on my site, it only shows the "friendly activity" feed on the page which seems to be ONLY the people that have checked in to the restaurant. Is it because its a "place" that its doing this? And I may need to make it a business rather than location to adjust the feed?
Is there a settings somewhere that will change this or something? Other wise I have no idea!
Add this parameter to your Like Box code:
&force_wall=true
The parameter is listed in the "Attributes" section of the Like Box page, but Facebook forgot to include it as an option in the tool that creates the Like Box code.
To expand on this "force_wall - for Places, specifies whether the stream contains posts from the Place's wall or just checkins from friends. Default value: false."
So in the second bit of code (not the script), you will need to add the force_wall parameter similar to this:
<div class="fb-like-box" data-href="http://www.facebook.com/pages/XXXXXXXXXXXXXX" data-width="595" data-show-faces="true" data-stream="true" data-header="true" force_wall="true"></div>
I think this should be data-force-wall="true" , but it still has no effect... it seems this issue really relates to facebook URLs that still use the ".../pages/..." segment

get fbml comments to automatically show form

I'm writing facebook app in fbml (not in iframe).
I added comments with <fb:comments ...> and it appears to work.
However, to add a comment, user has to click Add a comment... link to see the textarea and post button.
I am wondering is there a way to automatically show the form?
I want it to really look like here:
developers.facebook.com/docs/reference/plugins/comments
(with or without the like button)
well... to answer my own question:
it's documented at
developers.facebook.com/docs/reference/fbml/comments
The showform parameter.
Maybe it will help someone.