AHP Sitewide Recent Posts – hack 2.1ish

It’s funny how things happen to fall into place. Jacob over at 912Candidates.org was lamenting over the issue of not keeping the main page up-to-date. A few of the state sites have been posting updates, but Jacob has been a little busy and didn’t have anything to put on his front page. If only, he thought, there was a way to show the posts from the other sites. Well, what do you know, I was just playing around with a plug-in that did that. After pointing Jacob to the example on NC Freedom, he came back with some changes. The biggest change that he wanted was to use the flag icon I was using for each site instead of the avatar for the user.

When I created the one off Gold List plug-in for the 912Candidate site, I used avatar images that depict state flags. I decided to be a little creative and spice up the list with these flags and it turned out really well. Initially I had some issues getting the flags to work, because I needed an easy way to get the file name based off of the site. Each state site used the state abbreviation and the file names used the full name of the state. I didn’t want to rename all the image files, so I created an array to hold the values.

// state list
$stateList = array( 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California',
'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'DC' => 'District of Columbia', 'FL' => 'Florida',
'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa',
'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts',
'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska',
'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina',
'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island',
'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont',
'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin',  'WY' => 'Wyoming'	);

By having the array, I could always add more values or use either the initial to get the name or the name to get the initial.
I updated the code to search through the array and match up a substring of the blog link to the state abbreviations. If an abbreviation matched, then the code for adding the image is added to the variable. I replaced the avatar variable value with this new variable. It makes for a nice effect on the main page of 912Candidates.

foreach ($stateList as $abbr => $stateName){
if($abbr == strtoupper(substr($blog_link,strpos($blog_link,'org') + 4, 2))){
$this_blog_image = '<img src="/resources/flags/' .
$stateName .
'.gif" height="55" width="55" border="0" align="left" style="padding-right: 5pt;" />';
}
}

About DeanLogic
Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.

About DeanLogic

Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.