Displaying most popular post on Tumblr blog - tumblr

I've been tasked with adding "Most Popular" functionality to a Tumblr blog. Essentially, when the Most Popular button is clicked, I need to display either a single post, or a list of posts, ordered by their popularity. The popularity will be calculated based on the number of "notes" that the post has.
Does anyone have a suggestion on the best way to go about this? I can't find anything baked into their theme customization at http://www.tumblr.com/docs/en/custom_themes#search. Is going the API route the only way to accomplish such?

Well, I'm no expert with Tumblr but I have worked a fair share with the API for a project I'm developing. From my experience it seems you would need an API to get all of the posts note count. Using a theme I know to order the posts shown on the page without an API key, but to go further back you'd have to use a javascript plugin or just use the Tumblr API (it's surprisingly easy to use)
From my short time I just spent thinking about the issue, you could put a NoteCount on each of your posts (hidden with CSS or not; up to you) and then use the API's notes_info to obtain all of those numbers and compare them. You'd then store how ever many posts you want (according to the note count) in an array and use that array on the page you want. It seems like a lot of work, but I'm not sure how else you could do it
EDIT
After investigating the issue a bit, I found that note count is far from a consistent feature on Tumblr. There is no one class that all note counts share nor is the text around it consistent. It seems that you would have to do it on an individual blog basis. Once you obtain the HTML for the posts, through a script or the API, you can run a function similar to the following which uses regex to detect where the note count
var posts = document.querySelectorAll('.post'), // Get all posts (*most* blogs have this, not all)
noteExpr = /with ([0-9]+) notes/, // Get any numbers between "with " and " notes"
noteCounts = [];
// Creates an array filled with all of the note counts
for(var i = 0; i < posts.length; i++) {
noteCounts.push(noteExpr.exec(posts[i].innerHTML)[1]);
}
// Do something with noteCounts
Demo, using posts from one of my favorite blogs MotionAddicts
Some more examples using sites I look at:
For 58 notes use />([^>]+) notes/
For <div class="notecount">Notes: 218</div> use /Notes\: ([^>]+)</
The downside is this has to be customized for each blog if they vary in the format, but it is the only way I know how to without using the API, even then I'm not sure there is a better way
Other info:
Studiomoh had a similar plugin but it only works for pictures
Example of how to include a NoteCount
How to include a note count when there are no notes

Related

How to get posts orderby comment_count ascending and where to place the code? (Wordpress REST API)

I am a complete beginner when it comes to extending Wordpress REST API. I need to extend the API so that a request to /wp-json/wp/v2/posts?orderby=comment_count&order=asc would yield a response with posts that are ordered by comment count in ascending order ie. posts with the least amount of comments appear first.
I skimmed through the REST API Handbook and watched a couple of YouTube videos, but found no answer to my problem. I found this answer and it looks promising, however I'm not entirely sure if the code provided there fits my needs. From what I could gather WP_Query class is what I'm looking for, but I don't know how to make use of it. My second problem is that I don't know where exactly to place any code I may have stumbled upon ie. which file is supposed to play host to the code eventually?
I would greatly appreciate detailed answers and possibly sources for more information regarding this topic.
According to WordPress documentation orderby only accept following parameters:
author, date, id, include, modified, parent, relevance, slug, include_slugs, title
But you can add custom parameters to orderby if you have access to Wordpress website code. Please follow the below URL:
https://www.timrosswebdevelopment.com/wordpress-rest-api-post-order/
Let me know if you need more help.

Should I use dynamic pages or actual files for blog?

I've seen news sites (CNN, Fox News, etc.) use HTML files as their post content. For my blog, I currently use dynamic pages (e.g. www.example.com/post/?id=3).
I'm wondering if this is the correct way to go, mostly because AdSense won't accept /post/ for ads. Is this because it's just pulling up /post/ & not the id?
So basically, which way do you recommend? Thanks
It depends on the contend of your page. But basically the good way is to create easy to read links like:
http://example.com/drive-to-norway
It's because it's easy to read for people and before clicking the user knowns what it could be (instead for example: http://example.com/id=3)
Some bigger pages do not use that convention because they for example sell a lot of similar items and having named, unique links without any numbering isn't possible/easy for them. Like I wrote at the beginning - it depends on content.

How often a single news is shown

I'm using TYPO3 7.6 and the extension news from Georg Ringer. I'm looking for a way to count, how often a news is shown in the singleview? And I want to output this value in the news singleview.
In my opinion there are 2 possible ways which would still care about performance and let the detail view cacheable.
1.) If you use Google Analytics, Piwik, ... use its API to get the correct counts from there and put it back. This could be done by a scheduler task which runs every x hours/minutes
2.) Use a tracking pixel. Insert a tracking pixel which is connected to a php script (for further reading, google for eID) which will be called with every hit. Then you just need to write it back.
IMO there is no extension for neither of those 2 solutions available in public. However I did something similar as solution #2 which can be found at https://github.com/georgringer/newsmostread

Google Rich Snippets warnings for hCard

I get the following errors from the Google Rich Snippet Tool for my website http://iancrowther.co.uk/
hcard
Warning: This information will not appear as a rich snippet in search results results, because it seems to describe an organization. Google does not currently display organization information in rich snippets
Warning: At least one field must be set for Hcard.
Warning: Missing required field "name (fn)".
Im experimenting with vcard and Schema.org and am wondering if I'm missing something or the validator is playing up. I have added vcard and Schema.org markup to the body which may be causing confusion. Also, I am making the assumption I can use both methods to markup my code.
Update:
I guess with the body tag, I'm just trying to let Google discover the elements which make up the schema object within the page. I'm not sure if this is a good / bad way to approach things? However it lets my markup be free of specific blocks of markup. I guess this is open to discussion but I like the idea of having a natural flow to the content that's decorated in the background. Do you think there is any negative impact? I'm undecided.
I am in favour of the Person structure, this was a good call as this is more representative of the current site content. I am a freelance developer and as such use this page as my Organisation landing page, so I guess I have to make a stronger decision of the sites goals and tailor the content accordingly, ie Organisation or Person.
I understand that there is no immediate rich snippet gains, but im a web guy so have a keen interest in these kind of things.
With schema testing, I find it easiest to start from the most obvious problem, and try to work our way deeper from there. Note, I have zero experience with hcard, but I don't believe the error you mentioned actually has anything to do with your hcard properties.
The most obvious problem I see, is that your body tag has an itemtype of schema.org\Organization. When you set an itemtype on a dom element, you are saying that everything inside of that element is going to help describe that itemtype. Since you've placed this on your body element, you are quite literally telling Google that your entire page is about an organization.
From the content of your page, I would recommend changing that itemtype to schema.org\Person. This would seem to be a more accurate description. Once you make that change and run the scanner again, you may see more errors relating to the schema and we can work through those too (for example, you'll probably need to set familname and givenName).
With all of that said, you should know that currently there are no rich snippets that you will gain from adding this schema data. Properly setting this up on your page, is only good to do, especially since we don't know what rich snippets Google or others will expose in the future, but currently you won't see any additional rich snippets in Google search results from adding these tags. I don't want to discourage you from setting this up properly but I just want to set your expectations.

How to Style Facebook Activity Feed

How do you implement custom css on a Facebook activity feed plugin? This related post does not fully answer the question. Is this the right way?
Where does the
<fb:tag name='link'></fb:tag>
go? Inside of of the
<fb:activity site="..." app_id="..." ></fb:activity>
outside of it, before or after? I'm sort of confused...
the only way i use activity feed is when its in a widget that will generically upate in all posts. Anyone who inserts these snippets into blog posts or other 'hard to find and edit later' posts and pages, will regret it
Why?
Because Facebook changes their script every month or so and the script snippet you inserted wont work anymore
I have hundreds of blank areas in blog posts where i inserted an activity feed and the script always stops working after some weeks when fb adds some code or changes the location of some script or renames a file and the old script has no canonical or generic way of readjusting.
There is no point in using a script which gets made obsolete every month and you then need to find all posts where you inserted the snippet and change it for the new working code.
Im always having to reinsert new code into my fb social widgets because they cease to function...
Not viable unless you take it into consideration. Only insert in spaces where oyu wil notice it when it stops working
As Facebook Answers answered, you cannot really style it with a custom CSS, nor via JS, as the activity feed widget creates an iframe.
The info from martincarlin87 is useful, but that is not exactly what you get with the Activity Plugin, which is what you meant I guess:
http://developers.facebook.com/docs/reference/plugins/activity/
For using this you cannot really interact with the Facebook API, it is a little world apart. By now... (July 12th 2012)
Facebook PHP SDK: https://github.com/facebook/php-sdk
Comes with some simple examples, I would suggest uploading it to your server and tinkering with it, Facebook has a steep learning curve but here at Stack Overflow there is even a Facebook section: facebook.stackoverflow.com so just take each step at a time and if you can't get it by reading the facebook docs: developers.facebook.com then you can always ask here and I'm sure someone will be able to help you.
Getting Started: http://developers.facebook.com/docs/reference/php/
Once you have made an app, you add it to your fan page and then you will be abel to test what information you can get using the Graph API Explorer: https://developers.facebook.com/tools/explorer
That post you refer to is a red herring I'm afraid. If you put any HTML between the activity tags it gets rendered BEFORE the iframe is added. So its a no starter, from what I can see. However, I eventually found a solution, which I gave on that thread. I am repeating it here in case somebody searching doesn't see the other thread.
I managed to customise an Activity plugin, after a great deal of effort.
You can see the result here:
http://www.quniverse.co.uk/shopdata/about_us.php
Feel free to post a comment on that site, it exists purely for test purposes so I'm not fussed what goes up there provided its clean.
I explain how I achieved this in the blog article posted here:
http://facebookanswers.co.uk/?p=302
To summarise briefly:
You cannot insert CSS into the activity plugin.
Rely on the fact it has a transparent background, and supply your own.
Turn off the header and supply your own.
You can specify a light or a dark font, a few fontfaces and a border colour.
If you read the blog article you will get a full explanation.