Posts Tagged ‘PHP’

Create a WordPress Archives Page with Yearly Headers

Mar
12
2010

Create a WordPress Archives Page with Yearly Headers

Category: Blog
Tag:

The Register by OgilvyAction

Feb
15
2010

this is the post copy

Category: Design

Link back to a post’s category archive

Jan
1
2010

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);
 ?>
Category: Blog
Tags: ,

Capture all subcats in a category dynamically

Dec
2
2009

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

Category: Blog
Tags: ,

Ogilvy Japan

Sep
28
2009
Category: Design
Page 1 of 212