• I downloaded and successfully installed the Related Posts hack. I did find one problem. When you validate the XHTML, the parser gives an empty tag warning (

      ). So… I added a few lines to the hack to make it validation-friendly. You can view the modified code on my website.

    Viewing 8 replies - 16 through 23 (of 23 total)
    • i agree ??

      I just grabbed from cvs, created a new scratch wp install.
      I created categories:
      – second
      — subsecond
      – third
      — subthird
      I created posts:
      Second, in second
      Second 2, in subsecond
      Second 3, in second+subsecond
      Third, in third
      Third2, in subthird
      Third3, in third+subthird
      I added include(‘./same_cat.php’); to top of index.php.
      I added
      <?php
      echo “<div class=’related’>Related Posts:“;
      echo list_posts_of_cat(get_the_category(), 5, 5);
      echo “</div>”;
      ?>
      … just prior to the include of wp-comments.php.
      Viewing the site outputs the expected lists of related/matching category posts.
      Then I added a duplicate, except using (…, 1, 1) to try the random. Got same thing every time.
      So I added to the top of same_cat.php on the line followin the opening <?php:
      srand((double) microtime() * 1000000);
      Now I get the random, expected result for the 1,1 case.
      Let me know what’s not working for you folks. I can’t find anything wrong with it here, unfortunately.
      -d
      https://www.chait.net

      where is same_cat.php?
      and adding srand((double) microtime() * 1000000); to my-hacks.php did not help… :p

      hmm, it works again. dunno what was wrong then.
      added the “srand((double) microtime() * 1000000);” to my-hacks.php (top)
      @sushubh: same_cat.php is the stuff in your my-hacks.php
      you don’t include something when you got all that stuff in there.
      thanks david

      this is my hack file:
      https://blog.sushubh.com/my-hacks.phps
      what to do?

      put the following on top of it:
      srand((double) microtime() * 1000000);
      (if you don’t start it somewhere else like your index.php…)
      that’s for randomizing the stuff.
      to view the related articles paste:
      <?php
      echo “<div class=’related’>Related Posts:”;
      echo list_posts_of_cat(get_the_category(), 5, 5);
      echo “</div>”;
      ?>
      before the comments in wp-comments.php (or where you want it)

      ok the line was there…
      now its at the top.
      still:
      https://blog.sushubh.com/archives/2004/04/30/first-day-without-a-job-in-a-long-time-is-very-eventful/ has related posts in date wise orders with the last 5 articles coming in.

      Sushubh –
      I just put up a new version on my site. Same location:
      https://www.chait.net/index.php?p=87
      to keep things clean, you might want to just include(‘same_cat.php’) into your wp-hacks file. makes it easier to upgrade. ??
      1. I added in the srand, to ensure everyone has it from now on.
      2. I added a new param in, after the MAX, RANDOM params, which is a postID to ‘ignore’. So you can now do within the posts loop:
      <?php
      echo “<div class=’related’>Related Posts:“;
      echo list_posts_of_cat(get_the_category(), 1, 1, $post->ID);
      echo “</div>”;
      ?>
      … and it will filter OUT the current post from the possible responses.
      3. At the top of the file are two new globals:
      $sameCatDebug = 0;
      $sameCatDebugout = ”;
      if you change the debug to 1, it will accumulate debugging information into sameCatDebugout. You can then do an echo, or write to a logfile, to capture the output. I tested it with
      <?php echo “<div id=’samecaterrs’ style=’font: 10px Times, serif’>$sameCatDebugout</div>”; ?>
      if you capture the output for me for a few runs, I’ll look at it and see if something seems off. The only thing that would cause it is if rand isn’t working, or if your total posts in a cat is <= requested amount.
      I’ll keep banging on it if I can get some debug output from you guys. BTW, watch for “randomize disabled” in the output, as that’ll show up in cases where random did get turned off bc of not enough query results. The output should be somewhat self-explanatory if you’ve read the code at all.
      -d

    Viewing 8 replies - 16 through 23 (of 23 total)
    • The topic ‘Related Posts’ is closed to new replies.