WordPress: Post abstraction

At Metro we use WordPress but more and more logic is shifting to web services (so that we can order content algorithmically).

Currently that means we need to write different view logic depending on whether data comes from the WordPress database or from a web service.

The solution? Abstract it. For example.

Data from WP_Query

// WP_Query specific code
$the_query = new WP_Query( $args );
$ds = Metro_Data_Source( $the_query );

// Abstracted code
echo $ds->get_the_ID();
$ds->next_post();

Data from a web service

// Web service specific code
$ds = Metro_Data_Source( 'http://api.metro.co.uk/blah', CACHE_TIME );

// Abstracted code
echo $ds->get_the_ID();
$ds->next_post();

Will probably get complicated with things like images though…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s