WordPress.org

Support

Support » Plugins and Hacks » Related Posts

Related Posts

  • 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 15 replies - 1 through 15 (of 23 total)
    • Weird. Hey mark, can you check out the version on my site:
      http://www.chait.net/index.php?p=87
      .. I added a case to test the output being null. But it really shouldn’t be hitting that case unless something with the randomizer is going wrong. The count() case earlier detects <=0 counts and should generate proper xhtml.
      What case were you seeing the bad xhtml?
      -d

      Something in the randomizer did appear to be going wrong, but it was intermittent. Adding that bit of code appeared to have solved the problem.

      Cool. Glad to hear it.
      and if you mean MY site validation, it has gotten cleaned up a lot. It generally had to do with some of my internal link generation code not doing htmlentities calls on the title/alt text and body text before echoing. But the same_cat lib uses the wp link-builder fns, so if that’s where it’s failing, I’m not sure what I’m doing wrong. Again, might be that I need to be calling htmlentities, but I’d think the link-builder would do so.
      -d
      http://www.chait.net

      Chait, need some help…
      the hack works fine. but there is no randomization… 🙁
      it picks the latest five post from the categories…

      you calling it like:
      list_posts_of_cat($somecat, 5, 5)
      to get 5 random (of 5 max) posts? if you want all random, both numbers should be the same.
      my popular-posts code uses very similar code (I pulled it from there…), and I do something like ($somecat, 6, 3), giving me 6 total, but fix the first three as the actual first three, and the second three as random from the rest of the list..
      Let me know if that didn’t help any, if it’s simply busted. I looked at the code, fixed one minor thing, but you should still be seeing some randomness…
      -d

      echo list_posts_of_cat(get_the_category(), 5, 5);
      using this and i get the latest 5 posts…

      That’s the same code I use on my single-post pages. Pick any article, look at the left sidebar ‘similar posts’ list. refresh the page. it changed! 😉
      I’m running older code, possible that something changed in the format of the array returned by get_the_category that is now failing weirdly?
      Where/when in your site are you using that call?
      -d

      @davidchait, I looked at the code in the WikiPage, and it seems like for the functions, some of the variables are fixed, in the function call.
      For example
      function list_posts_of_cat($cat_array, $max = 8, $randomize = 0.....
      shouldn’t $max and $randomize not have have 8 and 0 assigned to them?
      Just something I noticed.


      <?php include(ABSPATH . 'wp-comments.php'); ?>
      </div>
      <?php if ($name != '') { add_count($p);}?>
      <?php } } else { // end foreach, end if any posts ?>
      Sorry, no posts matched your criteria.
      <?php } ?>
      <?php if ($name != '')
      {
      echo "<div class='related'>Related Posts:";
      echo list_posts_of_cat(get_the_category(), 5, 5);
      echo "</div>";
      }
      ?>

      this is where it is posted…

      2fargon –
      Those are default values. i.e., you can call:
      list_posts_of_cat(get_the_category)
      and it will output the last 8 in order by default.
      Any script I write typically has tons of default parameters, as does much of the WP code itself. Less useful in this particular script (5, 5 might be more useful), but you get the idea.
      Sushubh –
      I’ll try that out on my test site at home, see if it’s doing something weird, and if so I’ll debug it.
      -d
      http://www.chait.net

      still showing the last 5 latest posts.
      reapplied the hack and the code into index. still no use…
      using 21st nightly.

      I’ll go grab CVS and do a diff, see if anything jumps out.
      -d

      I looked through the latest code, and while there are changes happening all over the place, most of the category code should be working well (otherwise, you wouldn’t even get posts from that category!).
      Here’s some suggestions to help you help me debug this 🙂 :
      Try printing out values at various points…
      echo $c after it is set to count($catposts). It should probably be the lesser of total posts in cat or 10…
      echo $totalp, should be 10 (thus the 10 above).
      echo $max-$randomize, should be zero (for obvious reasons).
      echo $k after it is set to $i… I think it should be zero in this case.
      (WAIT)
      AHHHHH…. one thing DID just leap out at me. make sure you have a call to srand, needed for older PHP installations. like:
      srand((double) microtime() * 1000000);
      I have them sprinkled around, though there should just be one inside of wp-config. I don’t know what other subsystems use rand calls, but in theory not having srand called would lead the system to not return a random result, which would then iterate through the list in order, which would get you the first n posts found…
      -d
      http://www.chait.net

      heya david,
      i’m using your great hack on http://www.pixelblog.de and updated to wordpress 1.2 earlier this week (nightly builds).
      now i have the problem with sub-categories not be shown.
      can you workaround that or release a new version?
      sorry to bother but the hack is just great, i don’t want to dismiss ‘m 😉
      soulcore

      Will look into it. (cool layout btw — wish I could read it!)
      -d

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