Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Wordpress Plugin to feed CodeProject Technical Blogs

, 2 Mar 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
A WordPress plugin for CodeProject Technical Blogs feeding.

CodeProjectFeeder

In the beginning, everything was done manually.

After the third time I had to edit feed-rss2.php of wordpress to fulfill CodeProjects Technical Blogs requirements I now wrote my first (and last?) wordpress plugin.

As you may know, CodeProject allows you to publish articles through your current blog. See here for the FAQ.

As I am using wordpress, I started some time ago to submit blog entries into CodeProject. I had to find out myself, where to change which file.

Limit Published Articles

To limit the range of blog entries that are published at CodeProject Technical Blogs I use a ‘hidden’ feature and created a category named ‘CodeProject’ in my WordPress blog. On my Technical Blogs site in CodeProject I then used http://www.hjgode.de/wp/category/codeproject/feed/ for the feed input. Now only the articles marked with WordPress category ‘codepoject’ are feed to CodeProject.

Manually Changes Required in WordPress for CodeProject Technical Blogs

In feed-rss2.php I always had to add a <category>CodeProject</category> line below <channel>. Further I had to change the footer.php of the wordpress theme Win7blog that I use. There I added a rel=”tag” line as recommended by CodeProject.

The Pain of Doing it Again and Again

Now, the first manual change has to be done everytime you update your wordpress release. I had to to this at least three times before I start now with a plugin to I avoid changing the file again manually.

The Idea of a WordPress Plugin

I never wrote a WordPress plugin before, but I did some html, php and mysql coding before (ie the calendar on www.fewo-britta.de or the static pages at www.der-biedermann.de, which are generated from a db). But the learning curve was hard and it took me several hours to get the plugin working. I started with the plugin described at DevLounge in there “How to write a WordPress plugin” series. The article was the only one I could find that describes wordpress plugin development from scratch with a working example.

As I had problems adopting the code to my needs, especially the AdminPage, I had to rewrite the code a little bit.

My First WordPress Plugin

OK, what does the plugin do?

codeprojectfeeder_02.gif

The plugin inserts a rel=”tag” in your blogs page footer. This may look more or less good, depending on the theme you use. The footer always appears outside the themes footer. I could not find a way to let it appear inside the themes footer, if the theme uses the action hook wp_footer() ouside there footer block (here after the </div>:

<div id="footer">
 <p><?php bloginfo('name'); ?>

The plugin provides some checkbox options, so you can a) hide the rel=”tag” or b) dont use it at all.
To feed your publications to CodeProject technical blogs, you are recommended to add a category tag with the contents CodeProject in your RSS2 feed. To get this done by the plugin it installs two action hooks: the channel one: rss2_head and the ‘item’ one called rss2_item.

Here are the hooks I use in the plugin:

//Actions and Filters
if (isset($hgo_codeprojectfeeder)) {
 //Actions
 add_action('admin_menu', 'CodeProjectFeeder_ap');
 add_action('wp_footer', array(&amp;$hgo_codeprojectfeeder, 'addFooterCode'), 1);
 add_action('activate_codeprojectfeeder/codeprojectfeeder.php',
     array(&amp;$hgo_codeprojectfeeder, 'init'));
 add_action('rss2_head', array(&amp;$hgo_codeprojectfeeder, 'addChannelCode'), 1);
 add_action('rss2_item', array(&amp;$hgo_codeprojectfeeder, 'addItemCode'), 1);
 //Filters
}

The first hook is for the ‘Admin’ settings page.
The second one for the blog footer page.
The ‘activate_…’ hook is for initializing the plugin.
The rss2_head and rss2_item hooks are used to insert <category>codeproject</category> into the RSS2 header (<channel>) or <item> code.

Formatting of the rel=”tag” link

If you dont like the formatting of the rel=”tag” link, you can edit the plugin file codeprojectfeeder.php from inside WordPress, just click “Edit” below the “CodeProject Feeder Plugin” on the Manage Plugins page in your WordPress installation:

codeprojectfeeder_01.gif

codeprojectfeeder_04.gif

/*
 Adds the rel TAG to the footer
 */
 function addFooterCode() {
   $content = '';
   //debug
   //echo '<!--<span class="code-comment"> addFooterCode was called --></span>';
   $devOptions = $this->getAdminOptions();
   if ($devOptions['use_reltag'] == "true") {
     if($devOptions['hide_reltag'] == "true"){
       //using the style option you can adjust the link appearance
       $content = '<a style="display:none; text-align:center; font-size:x-small; " 
       href="'.stripslashes($devOptions['reltag_content']).'" rel="tag">CodeProject</a>';
       echo $content;
     }
     else{
       $content = '<a style=" text-align:center; font-size:x-small; " 
       href="'.stripslashes($devOptions['reltag_content']).'" rel="tag">CodeProject</a>';
       echo $content;
     }
   }
 }

You can change the appearance of the footer text with the css inline style statements, as there are already “text-align:center; font-size:x-small;”

With the other options of the plugins admin settings page you specify, if you like to have the category tag within channel for all pubilcations or inside every item. You should not use both, it does not make sense.

Plugin uses checkboxes instead of options

As you can see from the codeprojectfeeder.php code, I have changed the way yes/no options are used in the settings admin form. Instead of the very long, hard to manage lines, I use the shorter form and checkboxes:

<p><INPUT TYPE="CHECKBOX" id="codeprojectfeederUseRelTag" 
    name="codeprojectfeederUseRelTag" value="true" 
    <?php if ($devOptions['use_reltag'] == "true") {
    echo 'CHECKED'; }?>

instead of

<p>
<label for="devloungeHeader_yes">
<input type="radio" id="devloungeHeader_yes" name="devloungeHeader" value="true" 
    <?php if ($devOptions['show_header'] == "true") { _e('checked="checked"', 
    "DevloungePluginSeries"); }?>

You can download the codeprojectfeeder plugin as zip: DOWNLOAD:CodeProjectFeeder - A Wordpress plugin

Development and Debugging

As you can see in codeprojectfeeder.php, there are some comment lines with a //debug line before. I used these during development to find my typos and bugs.

The plugin was tested on a lampp system (an Acer Aspire One A150 netbook), a windows xampp system and finally in my blog. Just be warned that due to caches or whatever of the testing lampp/xampp systems, sometimes the output was not altered and nothing changed, although source code was changed. I had to restart apache/mysql to get correct results. The RSS2 feed was sometimes cached by firefox/ie and was hard to debug, as the contents did not change although the source code was changed.

Installation

Just unzip the files into a dir called codeprojectfeeder below your wordpress wp-content/plugins dir or unzip the directory codeprojectfeeder into your wordpress plugins dir. Then Activate the plugin and select the CodeProjectFeeder settings you like.

Finally

Now, you and me dont need to change the feed-rss2.php file manually any more for CodeProject Technical Blogs.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

hjgode

Germany Germany
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberCale Dunlap10-Apr-12 0:10 
A very handy plugin for WordPress. Great work!
QuestionThanks PinmemberRiaan Booyzen15-Feb-12 19:57 
QuestionI was looking for this PinmemberWebBiscuit13-Jul-11 13:47 
AnswerRe: I was looking for this PinmemberWebBiscuit13-Jul-11 14:22 
GeneralRe: I was looking for this Pinmemberhjgode2-Sep-11 21:06 
GeneralGoodness, thanks. PinmemberWatcharakorn Wanich19-Apr-11 0:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 2 Mar 2010
Article Copyright 2010 by hjgode
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid