Created
December 5, 2012 02:25
-
-
Save ginsterbusch/4211564 to your computer and use it in GitHub Desktop.
Quick hack of a rudimentaty "API" for subtle-patterns.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WP nastyness with Subtle Patterns for a extremely simplistic "API" | |
* | |
* æauthor Fabian Wolf | |
* @link http://usability-idealist.de/ | |
*/ | |
// bootstap WP framrework | |
require_once('../../../wp-config.php'); // assuming this file is sitting in some sub directory like wp-content/theme/my-theme/ | |
// predefine some return value | |
$strReturn = json_encode( array('return' => 'no_data_found') } | |
// fetch posts based on category 'patterns' | |
$oCategory = get_category_by_slug('patterns'); // assuming we dont want to change the ID but go by slug | |
if( $oCategory != false ) { // only do this if we got the category_id | |
$arrQuery = array('category' => oCategory->term_id, 'order_by' => 'post_date' ); | |
$arrPosts = get_posts( $arrQuery ); | |
if( !empty( $arrPosts) ) { | |
// prepare the nasty JSON data ... | |
foreach ($arrPosts as $iCount => $post) { | |
setup_postdata($post); | |
if( has_post_thumbnail( $post->ID ) != false ) { | |
// Houston, we have a pattern image! | |
$strImageURL = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); | |
} | |
// dump it all into an array | |
$arrRow[$iCount] = array('title' => get_the_title(), 'description' => get_the_excerpt(), 'image' => strImageURL, 'date' => get_the_time('%s') /** Unix Epoch Time timestamp */, ); | |
} | |
// add success mesage | |
$arrRow[] = array('return' => 'sucess'); | |
$strReturn = json_encode( $arrRow ); | |
} | |
} | |
// lets END THIS here ... | |
exit( $strReturn ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment