The Right Way To Build WordPress As A Community News

written by aext on January 2, 2010 in WordPress with 63 comments

WordPress is getting popular now and everyone is switching to use WordPress because we can build anything with WordPress: WordPress as a magazine, WordPress as a bulletin board, Video site ….. Today, I would like to put all my love for WordPress into this tutorial to explain how to build WordPress as a Community News, … but in a right way.

In WordPress, the popular plugin for us to build community news submission is FV Community News which is being used on a lot of blog pages. This plugin is really useful to add related articles from other blogs to your sidebar. Adding them manually takes lots of time we don’t have. However, FV Community News stores submissions in another table in database. That’s the problem now for someone want to build a community website where everyone can submit their news to. You can check some design community news website such as: webdesign-ne.ws, design-newz.com, scriptandstyle.com… or check my second website at whofreelance.com. They and I are not using FV Community News to handle users submissions. The plugin on these websites is TDO Mini Forms because TDO Mini Form help users submit their posts as WordPress posts.

1. Setting up your TDO Mini Form.


First, very simple, download this plugin in zip format and extract the files to a subdirectory, called tdo-mini-forms, of your plugin directory. i.e. /path_to_wordpress/wp-content/plugins/tdo-mini-forms. Then, go to plugin menu in WordPress Admin and active it. Make sure you then configure it via the main TDOMF menu in the WordPress Administration backend.

I would like to forward you a link to Tutorial Video for TDO Mini Forms! . The video is pretty good too as it shows you how to create a submission form and an edit form.

And after you know how to use the TDO Mini Form, create a submit page with the form as below:

Create new page item in WordPress Admin and name its title as “News Submission”. In my case on whofreelance.com, the permalink for this page is http://whofreelance.com/news-submission/. After that, type something about the the copyright or something like the rules for submission. Don’t forget to implement the form to this page by put this code below:

[tdomf_form1]

And this is what you get:

Now, at this step, you already done for the community website that publish users’s news submissions. No more step required for doing like all of the community design news websites I referred at the beginning of this post.

If you have not only one website or blog, and you want to display these submissions on another websites, the best way is fetching rss feed from it. However, the problem is you cannot get the direct urls to original posts because we save the users’s post urls as post meta tags. B default, post meta tags were not included in the feed. You might have a little confusing because css-tricks.com is fetching the news from scriptandstyle, or you can see I’m doing the same with AEXT.NET which are fetching users’s submission on whofreelance.com. That’s why you need to go to next step.

2. Modify the feed of the submissions.


Each post when submitted to your WordPress will appear on your feed, right? Someone will say: “Hey, it’s easy, I have the feed here, I can fetch rss and display the submissions on other websites”. The answer is “Yes, you can”. However, you can just only fetch the post title, post url or anything is belong to the article submitted except post meta tags. Refer to the first image above, I highlighted the post_url meta tags because it will be the most important part of community news.

ScriptandStyle published a post explains how to Add Custom Values To Your WordPress RSS Feed. That would be a good solution for you to put post meta tags to the feed, right? This hack will work. However, you will realize that everything (your changes) will be lost when you update WordPress.

Here is better solution. In your WordPress Admin, create another page. What’s the heck this page for? For your feed. Because you will lose your changes when you update WordPress if you hack into feed-atom.php file. So, why don’t you create your own rss file and put it into your template folder, and create a new page in WordPress Admin with the content is the content of rss file? Everything will be fine if you update WordPress or not.

[smartads]

Simple as I did, in your theme directory, create new file name it “communty-feed.php” or something you like (just keep it in secret), then copy all the content of feed-atom.php in wp-includes folder and paste into your new file you have just created.

Important: Insert these code at the head of this file.

<?php
  /*
  Template Name: Community Feed
  */

$numposts = 10;
$posts = query_posts('showposts='.$numposts);

Without query the posts and number of posts to display, the content of your new feed file will be empty and only the title of page will appear in the feed.

Set the Template Name on the head will help WordPress recognise the file, so that you can create new page in WordPress admin with the template is this page. Furthermore, add the direct url to your feed by put these code within the entry tag.

<entry>
    <author>
        <name><?php the_author() ?></name>
           <?php $author_url = get_the_author_meta('url'); if ( !empty($author_url) ) : ?>
             <uri><?php the_author_meta('url')?></uri>
           <?php endif; ?>
    </author>

    <!-- this is what we add -->  
    <directurl><?php echo get_post_meta($post->ID,'post_url',true); ?></directurl>

    <title type="<?php html_type_rss(); ?>"><![CDATA[<?php the_title_rss() ?>]]></title>

To set this page as page template, following this image:

And now, you are fine with the feed, you will not see the post meta tags in any feed readers, but the feed still work like original feed.

Fetching feed on other websites


All the feed have the same basic structure. Each feed has its children tags, and in this case, our feed is:

We will fetch only the title, published date, and the link to original post of each item. In your functions.php file, create new function to fetch all the feed items. Remember that the total number of items will be fetched is 10 because we have limited the number of post displayed in our feed is 10 as above. Refer to the image right above, using simplexml_load_file, your function will look like:

function getFeed($feed_url) {
    $xml = simplexml_load_file($feed_url);
    echo "<ul>";

    foreach($xml->entry as $entry) {
         echo "<li>";
         echo "<span class='post-date'>Posted: ".date(  "F j, Y", strtotime($entry->published) )."</span>";
         echo "<h3><a title='Permanent Link to ".$entry->title."' rel='nofollow' href='".$entry->directurl."'>".$entry->title."</a></h3>";
         echo "</li>";
     }

     echo "</ul>";

}

In your sidebar, use this code to display the feed.

<?php getFeed("http://link-to-your-feed/"); ?>

Your result:

The feed can be display by different codes, this code is just an simple code I would like to put it into this tutorial.

Some code you will be interesting to take a look for example:

Conclusion


You see? we can build anything from WordPress. The only problem is the better way to transform it and do it in a right way. I hope this tutorial will help you build a better web community news for news submission. I would appreciate all the comment the help the tut more completed.