Breaking Up The Best of Show
Alan Levine aka CogDog barked this May 2nd, 2007 11:14 pm
I just got self distracted, not in twittter, but twiddling here with the blog. For quite some time, I have rigged together a ‘Page’ in WordPress that uses a RSS feed with info on all the presentations I’ve done going back to 2003. This was generated by sending the feed to the Feed2JS site to dynamically make the page.
I’m writing up notes here how it was done- the new thang is up at http://cogdogblog.com/best.php
What I did not like was that it grew rather long, so I decided to make it be a PHP script that would dynamically do the right thing per year. The first step was breaking up a long single XML file into smaller files, one per year, e.g. 2003, 2004, … 2007. Just cut n’ paste.
The idea is to have a web form in the page that presents a menu one can choose from- the thing with a WordPress page is I do not know of anyway to send it a PHP variable to represent the value for the year selected from the menu– as WordPress has its own way of shuffling variables around. So I took a backdoor approach, actually copying the code from my Indy Junior setup.
My method is that the new page created (small “p”) is not a WordPress Page (capital “P”), it is its own PHP driven web content. but with some bits of WP knowledge, I tap into WordPress to generate headers and footers. You can do this by (the exact set of divs may depend on your template):
<my ?php
/* Set up WordPress stuff */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<div class="post">
Here goes any of the content you want on the page!
blah blah blah.
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
So you set up a connection to WordPress to generate the header, sidebar, and footer, and you are free to do whatever you want in the middle.
So the first thing I need up front is an array for the values for the years I am covering (2003-2007), and some code to set a default value for the year if the script has not been sent one. So the changes up top make it:
<?php
/* Set up WordPress stuff */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
// array of all years
$all_years = array('2007', '2006','2005','2004','2003');
// if no year passedm give it default value
$year = ( !($_REQUEST['year']) ) ? $all_years[0] : $_REQUEST['year'];
?>
Next, I just need to generate a header and a menu for the main part of the page, inside the div:
<h2>CogDogBlog's Best of Show for <?php echo $year?></h2>
<form action="<?php echo $_SERVER['PHP_SELF']?>">
see the shows for
<select name="year" onChange="submit()">
<?php
foreach ($all_years as $key) {
$selected = ($key == $year) ? 'selected' : '';
echo "<option value="$key" $selected>$key</option>";
}
?>
</select>
<input type="submit" name="enter" value="go" />
</form>
Below this some text to declare what we are doing, and generate a link to the RSS feed appropriate to the year we are dealing with
<p>We regularly hit the dog show circuit, and below you will find our track record back to sometime in 2003. This content is provided as an RSS feed and rendered via <a href="http://feed2js.org/">Feed2JS</a>:</p> <a href="http://cogdogblog.com/wp-content/show/<?php echo $year?>.xml"> <img src="/images/rss.gif" border="0"> http://cogdogblog.com/wp-content/show/<?php echo $year?>.xml</a>
And then we just need to use some PHP to push the right value of the year into the Feed2JS code (zowie! PHP inside Javascript):
<script language="JavaScript" src="http://feed2js.org/feed2js.php?src=http%3A%2F%2Fcogdogblog.com %2Fwp-content%2Fshow%2F<?php echo $year?>.xml&chan=y&desc=1 &date=y&targ=y" type="text/javascript"></script> <noscript> <a href="http://feed2js.org/feed2js.php?src=http%3A%2F%2Fcogdogblog.com %2Fwp-content%2Fshow%2F<?php echo $year?>.xml&chan=y&desc=1 &date=y&targ=y&html=y">View RSS feed</a> </noscript>
And that does it! It pretty much looks like it is part of the main blog site, but actually is outside. Should I ever change the template for my header, fooder, etc, these pages all will go with the flow.
This entry was posted 1 year, 6 months ago and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
