Latest Posts v1.0 by Cypher


While looking for plugins for Jutia Group I stumbled upon Latest Posts v1.0. It is on the left side, under “10 Newest Entries”.

I needed some more functionality out of it so I took the liberty to modify the code a bit. Just to make it a tad more flexible.

I started by changing the function call for inside the template. I changed it from:


to


What this does is, before the function is called its existence will be verified. This will prevent your theme from braking and your pages loading halfway and then displaying errors when the function is called:

  • if you disable the plugin (now you can turn on and off the plugin without the visitors getting page errors)
  • the plugin file is moved, corrupted or deleted

In other words, if something happens to the plugin and you are unaware of the problem, your site will not brake. This of course is bad, but it will not have a negative effect on your site.

My next change was to make the number of posts being displayed flexible. With other plugins and the ability to call the function in any page or post you might want to display different number of posts at different places.

I started by deleting the variable

$max_posts

from the global declaration.

Then I placed that variable in the function declaration.

Old

function cypher_latestposts($before='', $after='
')

New

function cypher_latestposts($max_posts, $before='', $after='
')

Now when you call your function you can set the number of post to be displayed at the function call location. Like this:


In this example I want 10 posts. You can change this number to anything you want.

Here is an extra. Some of you might want to display your links in a list, others separated by a comma (no idea why), slashes, hyphens or as in the original just with a line breaker. So what you will do is change the function declaration like this:
From

function cypher_latestposts($max_posts, $before='', $after='
')

to

function cypher_latestposts($max_posts, $before, $after)

When you call your function just insert what you want to separate the links with. Here are some examples:

<?php if (function_exists('cypher_latestposts')) cypher_latestposts('10','
  • ','
  • '); ?> <?php if (function_exists('cypher_latestposts')) cypher_latestposts('10','+','
    '); ?>


    Discover more from Titan Fusion

    Subscribe to get the latest posts sent to your email.


    Discover more from Titan Fusion

    Subscribe now to keep reading and get access to the full archive.

    Continue reading