Posts Tagged ‘WordPress’
Let Users Know That Your Twitter Feed’s Down, Not Missing
The only thing worse than the good ‘ole “Fail Whale” when you try checking out a Twitter profile, is when Twitter’s slowness effects the content on your site.
A lot of sites are using Widgets and Sidebar space to display their user timeline. This can be very handy to display the last x number of posts (for info on how to to add a Twitter Feed, check out the post “Integrating a Twitter Feed onto Your Site“).
Link back to a post’s category archive
Kind of annoying that the only pre-set WordPress code for this type of thing prints the link and doesn’t let you use it as a variable. This is very useful as a “back” button and keeps the user within your site if they got to the specific post from outside, which wouldn’t be the case if you used a Javascript onClick=”history.go(-1)“. The only caveat here is if you have a post tagged in more than one category. This defaults to the category in the 0 position of the array returned from “get_the_category”, which I believe defaults to the category with the lowest ID#.
<?php $category = get_the_category($post->ID); $first_cat = $category[0]->cat_ID; $category_link = get_category_link($first_cat); ?>
Capture all subcats in a category dynamically
I’ve been working on two foreign language sites where they’re using a category of “English” (slug of “en”) to create an alternate page for English posts. In order to make certain elements on the category pages and single pages in the subcategories of “English” different than those on the pages in the native language, I had to write some code to dynamically pull in all of the subcategories of “English”.
<?php $en = “229″; // used the ID, not slug or name just in case they want to eventually rename the category
$i = 1; // place holder variable
$sub_cats = get_categories(‘child_of=’.$en.’&style=none&hide_empty=0′); // get all children and store in array
foreach($sub_cats as $sub) { // go through all of the sub categories
$english_cats[$i] = $sub->cat_ID; // go through the array and just pull out the category IDs and store in new array
$i++; // go to the nextarray element
