There’s quite easy way to connect WordPress and Flash. I’m talking about pulling dynamic content to Flash, the way you insert swf to your site is just another story. In both cases you’ll need swfobject.js in order to follow standards-friendly method of embedding Flash. I have never tried to use any of WordPress available plugins, somehow I rather include it manually, so at this point I’m not sure whether it’ll work with plugin. I guess it should.
Are you about to replace standard, HTML navigation with Flashed one? Do you want to make some recent posts slider in sidebar? Maybe some cool tag cloud in footer? Flash can be added whenever you like and do whatever you like. The most important fact about Flash is that it’s capable to load and process XML and that’s exactly how we are about to exchange data between WordPress and Flash. Once the data has been loaded into Flash options to display it on some non-standard and interesting way are endless.
For the demonstration purpose we are about to generate the list of latest Posts and send it to embeded Flash file. Each list item will have a title, post date, number of comments, thumbnail image (if any), post category and a link back to post details.
Let’s create and save in our theme’s folder new file called ‘flash_recent.php’. I don’t know which theme you are using but it doesn’t matter in deed, it’ll work with any properly activated WordPress theme. Our new file should be able to connect to database and get required information. In the same time we’ll output results in standard XML format readable to Flash.
<?php
// get connected
require_once( '../../../wp-config.php' );
// variables
$xml = "";
$num_of_posts_to_display = 5;
// query posts
query_posts( 'showposts=' . $num_of_posts_to_display . '&post_type=post&post_status=publish&order=DESC' );
if( have_posts() ) : while( have_posts() ) : the_post();
// category ID
$category = get_the_category();
// get first thumbnail path
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post->post_content, $m );
// format XML
$xml .= '<item>';
$xml .= '<title>' . $post->post_title . '</title>';
$xml .= '<postlink>' . get_permalink() . '</postlink>';
if( $m[ 1 ] ) $xml .= '<image>' . $m[ 1 ][ 0 ] . '</image>';
$xml .= '<category>' . $category[ 0 ]->cat_name . '</category>';
$xml .= '<catid>' . bloginfo( 'home' ) . '?cat=' . $category[ 0 ]->cat_ID . '</catid>';
$xml .= '<date>' . date( 'M j, Y', strtotime( $post->post_date ) ) . '</date>';
$xml .= '<comments>' . $post->comment_count . '</comments>';
$xml .= '<excerpt>' . get_the_excerpt() . '</excerpt>';
$xml .= '</item>';
endwhile; endif;
// output results
echo $xml;
?>
In order to check whether an output is OK you should type in Browser’s address bar full path to ‘flash_recent.php’ file. For eample: http://yourdomain.com/wp-content/themes/some_themeName/flash_recent.php.
Well, next time we gonna learn how Flash can handle parsed XML. I bet many of you already know how but for the sake of those who doesn’t – expect to find an answer in part#2 of this tutorial.
Yes, have a look:
http://themeforest.net/item/sofa-designer-folio/30472
or
http://themeforest.net/item/sofa-designercorner/33817
Subscribe to RSSStay up to date with my blog
Follow me!Follow me or get followed
iPadCaseDen.comiPad cases, folio cases and bags review