Home > Nemasket.net > Nemasket.net update

Nemasket.net update

Technical gibberish warning
I’ve been using nemasket.net as a feed aggregator. It pulls in headlines from all the local blogs that I follow. It is using WordPress(blog/cms software) and a plugin called feedwordpress – an RSS and atom syndication doohickey.

This has mostly been working OK but had a manual component to it. Some feeds include the body of the post, a summary of it, or nothing at all. What I wanted was the post headline being a link to the original site (gladys, bumpkin, CST, etc) and the body of the post to be a citing of a small portion of the original post. I just couldn’t find a way to do it and ended up manually citing the original article myself.

As a computer guy, what I lack in skill I make up for in laziness. I can’t stand doing a task repeatedly. It drives me nuts. This lazy instinct finally drove me to automating the citing portion.

This post is to help me remember how I did it and maybe attract a more elegant solution from some superior geek that stumbles upon it.

WordPress supports themes – templates that give the site a very different look and feel depending on which theme you use. Inside the theme directory is an index.php file that controls the display on the main page – usually a listing of the site’s posts. With a little trial and error, I figured out that this line was displaying the actual text of the post:

   <?php the_content(__('Read more...', 'inove')); ?>

I re-wrote and added this stuff.

  <?php      # capture output buffer     ob_start();     # output post body     the_content(__('Read more...', 'inove'));      # assign post body(output buffer) to a string     $mycontent = ob_get_clean();     # get rid of any embedded php or html     $mycontent = strip_tags($mycontent);     # truncate the post body to 300 chars + ...     $myshorty = substr($mycontent,0,300);     $mycontent = $myshorty . " ...";     # print the post body     echo "<i>$mycontent</i>";  ?>

Short version
Nemasket.net should now take care of itself. Any readers using it to follow the local Internet stuff won’t have to wait for me to update anything.

If you have any blogs or local sites, you’d like include, drop me a comment.

UPDATE
As always, when something seems too difficult, it usually means there is an easier way. A builtin WordPress function will do the same thing my 7 lines of code do. This one line does pretty much the same thing – truncating the post at 55 words:

   <?php the_excerpt(__('Read more...', 'inove')); ?>

Work smarter not harder.

Categories: Nemasket.net Tags:
  1. No comments yet.
  1. No trackbacks yet.

Switch to our mobile site