cialis online pharmacy generic xenical cheap cialis online cialis generic viagra online in canada buy cheap levitra online cialis without a perscription order viagra uk no prescription flagyl cheap generic levitra buying viagra in the uk cheap viagra approved cialis deltasone online buy viagra online without prescription non prescription cialis buy orlistat uk buy cialis in india prednisone 60 mg female viagra online buy viagra without prescription celebrex prescriptions buy cialis canada best prices viagra alternative to prednisone cheapest generic levitra levitra 5mg cheap viagra cialis on line buy xenical without prescription online accutane canadian health care prednisone no prescreption viagra online generic female viagra europe buy cialis low price cheap india viagra

An Alternative Way To Unburying Old Posts In WordPress Using PHP

As a blogger, you want your older posts to remain relevant to your new readers by making them visible on your site’s main page. And though there are various ways to achieve this (e.g. plugins, archive pages), Karol K. came up with his own unique and clever method by using PHP.

With his method, you’ll be tinkering a bit with the index.php file. The whole idea is to create some space right after the first post listing and display a random archive post as the second one. The steps involve is as follows:

  • Find the loop.
  • Include “$first_post_marker = true;” just above the loop.
  • Locate the closing “endwhile;” of the loop.
  • Include the following code directly above this “endwhile;”:
if($first_post_marker && strlen($_SERVER['REQUEST_URI']) < 2)    //to make sure that we’re on the first page
$week = date(‘W’);
$whatyear = date(‘Y’)-1;
$custom_query = new WP_Query( ‘year=’ . $whatyear . ‘&w=’ . $week . ‘&orderby=rand’);    //random entry from the archive; same week, only one year back
/* ==================================
Here’s where you display your post, use the same formatting you’re using in the main loop.
Usually calls like: “the_title();” and “the_content(”);” and so on.
================================== */
break;    //we only need one post
$first_post_marker = false;

Feel free to tell Karol what you think of his method by clicking here.

Related Posts

Adding Instagram Badges to Your WordPress Profile

How to Create a Custom WordPress Registration Form with Flat UI

How to Create A Basic Hipster-Style Layout

How to Style Nav Links Using Floats With HTML5 and CSS3