24/06/2008

I have had a lot of feedback over one of my first ever posts, Wordpress: Sliding Doors details how you can convert wp_list_categories into a subtle HTML markup so that we can use the sliding doors principle. However the method I described in my original post no longer works. After a lot of thinking and head scratching I have discovered a new, if not better, way to achieve the same results.

(more…)

17/03/2008

The FeedBurner Chicklet is a great tool for publishing your feed, it does look a bit ugly though. By using the powerful FeedBurner API you can grab your feed count without the Chicklet. This means you can put it anywhere on your site!

Step 1: What you need

We are going to be using PHP’s cURL library, which means, full details on what you need for this package can be found on php.net. You will also need your FeedBurner URL.

Step 2: The Code

First of all we need to create the URL to the data for our feed. We are using the FeedBurner Awareness API to get the data. The API call is made up of 2 parts, the first being the call to FeedBurner, the second being the name of your feed (in FeedBurner).

$feed="http://api.feedburner.com/awareness/" .
         "1.0/GetFeedData?uri=YOURFEEDNAME";

Next we need to start our cURL session by initialising the PHP curl_init() call.

$curl = curl_init();

We use CURLOPT_RETURNTRANSFER to make sure the data is returned instead of being printed out to the browser. After we have done that we can set the optiona for the curl.

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Set the URL of the curl set options
curl_setopt($curl, CURLOPT_URL, $feed);
// Execute the fetch
$data = curl_exec($curl);
// Close the connection
curl_close($curl);

After we have got the data we can parse the XML and find the bit we are looking for (circulation).

$xml = new SimpleXMLElement($data);
$feed = $xml->feed->entry['circulation'];

Step 3: Putting It All Together

$feed="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=dtsn";
$curl = curl_init();
curl_setopt($curl , CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl , CURLOPT_URL, $feed);
$data = curl_exec($curl );
curl_close($curl );

$xml = new SimpleXMLElement($data);
$feed = $xml->feed->entry['circulation'];

The subscription count is included in the variable $feed, which you can put anywhere. Or if you don’t have any imagination like me you can just put it in your side bar. It makes a great alternative to the Chicklet.

24/08/2007

This article has been updated please see here.

I have only just started using Wordpress and first on my list of things to do was to create a custom theme for the blog. Theme creation is simple in Wordpress just copy and paste your HTML code into another theme. The one area I did have trouble in was creating a menu which used the sliding doors principle.

Typically root navigation in Wordpress is achieved through wp_list_pages which outputs a html list (<li>) of the pages complete with their links. However the sliding doors principle requires an extra tag in the list structure i.e. <span>.

Wordpress Outputs:

<li>
      <a href=<a href=”http://www.dtsn.co.uk”>www.dtsn.co.uk</a>
</li>

However we require:

<li>
     <a href=”http://www.dtsn.co.uk”><span>www.dtsn.co.uk</span></a>
</li>

To overcome this we use a little PHP and a SQL query to select all the pages from the database and display them in a custom list:

<?php
   $querystr = “SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status =
                    publish’ AND $wpdb->posts.post_type = ‘page’ ORDER BY $wpdb->posts.post_title ASC”

   $pageposts = $wpdb->get_results($querystr, OBJECT);
   if ($pageposts)
   {
      foreach ($pageposts as $post)
      {
         setup_postdata($post);
         $title = the_title(”,”,FALSE); //wp conditional statement
         ?>
           <li<?php
              if ( is_page($title) ) {
                ?> id=’selected’<?php
              } ?>>
              <a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
                 <span><?php the_title(); ?></span>
              </a>
           </li>
    <?php
    }
} ?>

The code above pulls out the database information regarding pages, we then call the corresponding wordpress functions (such as the_parmalink()) to insert the data in the correct place. The code above also applies a ’selected’ class to the menu item so that the user can determine which page they are on. Thus giving you the effect you see on this blog. This is done using one of Wordpress’s conditional statements (the_title()) which calls the title of the page you are currently on.