Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Problem ze skryptem wyswietlajacym ostatnie posty
Forum PHP.pl > Forum > Gotowe rozwi±zania > Skrypty forum
f4ngorn
Mam problem, mianowicie chcem uzyc skryptu ktory wyswietla ostatnie posty ipb. Pobiera on dane z bazy i wyswietla ostatnie X postow. Chodzi mi o to, zeby kazdy post byl w osobnej komorce. Glowilem sie troche ze znajomym i doszlismy do 1 mozliwosci, wstawic kilka skryptow na strone i zmienic zapytanie zeby kolejno pobierala ostatni, przed ostatni, przed przed ostani post, ale to jest polsrodek smile.gif Moze ma ktos jakies pomysly? Zamieszczam ponizej skrypt:

  1. <?
  2.  
  3. // **************************************** //
  4. // Original mod submitted by Miles Johnson. //
  5. // Completely rewritten by Anthony Petito.. //
  6. // V2.0: 4 April 2005...................... //
  7. // V2.1: 10 April 2005..................... //
  8. // **************************************** //
  9.  
  10. // This mod will pull the latest X posts from your forum and display them on your 
    website.
  11. // This new version will also handle forums that you do not wish to show (excluded forums)
  12.  
  13. // Put this file where your FORUMS are located (e.g, http://domain.tld/forum).
  14. // This should be in the same path as your conf_global.php file
  15. // I've commented most of the code so that it's fairly understandable, however, 
  16. // if you're unsure of what's going on here, stick to the comments on where to edit this file for your site.
  17.  
  18. // For this to work properly, copy the following code into your website. Change it to match the link to THIS file.
  19. /* <?php include("http://domain.tld/forum/latest_posts.php");?> */
  20.  
  21. /////////////////////////////
  22. // User Editable variables //
  23. /////////////////////////////
  24.  
  25. // Change this to the number of posts you would like to show.
  26. $posts = 10; 
  27.  
  28. // If you would like this mod to cut topics after a certain character length, leav
    e this at 1. Otherwise, change it to 0. 
  29. $showtopiclength = 1; 
  30.  
  31. // Length of title to display before cutting off. If topic title length exceeds this value, it is followed by ellipses (...)
  32. // Only useful if the above varaible is set to 1.
  33. $topiclength = 40; 
  34.  
  35. // Add forumid's to exclude from. For example, you might want to exclude your private forums so that posts from it
  36. // do not show up. Seperate each forumid by a comma and ensure there's no spaces in between.
  37. $forumexclude = "38,37,71,73,69,44,75,108,74"; 
  38.  
  39. // The following 2 lines can be changed to however you want the date and time to b
    e displayed.
  40. // Default date: dd month year
  41. // Default time: hh:mm ampm TIMEZONE (12 hour time)
  42. // For more information on how the next 2 lines can be changed, please reference t
    he README file.
  43. $datedisplay = 'd F Y';
  44. $timedisplay = 'h:i A T';
  45.  
  46. //////////////
  47. // Required //
  48. //////////////
  49.  
  50. require "ips_kernel/class_db_mysql.php";
  51. require "conf_global.php";
  52.  
  53. //////////////
  54. // Database //
  55. //////////////
  56.  
  57. $db = new db_driver;
  58. $db->obj['sql_database']  = $INFO['sql_database'];
  59. $db->obj['sql_user']  = $INFO['sql_user'];
  60. $db->obj['sql_pass']  = $INFO['sql_pass'];
  61. $db->obj['sql_host']  = $INFO['sql_host'];
  62. $db->obj['sql_tbl_prefix']  = $INFO['sql_tbl_prefix'];
  63.  
  64. // Connect to DB
  65. $db->connect();
  66.  
  67. // Query the DB with the supplied user inputted variables.
  68. $getposts = $db->query("SELECT posts, last_poster_name, last_poster_id, title, tid, forum_id, last_
    post FROM _ipb_topics WHERE (forum_id NOT IN ($forumexclude)) ORDER BY last_post DESC LIMIT $posts"
    );
  69.  
  70. // Format and display the results.
  71. while ($post = $db->fetch_row($getposts)) {
  72. $post[full_title] = $post[title];
  73. if ($showtopiclength == 1 AND strlen($post[full_title]) > $topiclength) {
  74. $post[short_title] = substr($post[full_title],0,$topiclength);
  75. $post[short_title] = $post[short_title]."...";
  76. }
  77. else {
  78. $post[short_title] = $post[full_title];
  79. }
  80.  
  81. $posted_on = date($datedisplay, $post[last_post]); // Need to change mySQL timestamp to something more human readable.
  82. $today_date = date($datedisplay, time()); // Grab today's date so we can compare it against the posted date
  83.  
  84. // If it was posted today, we want to display "Today, hh:mm AMPM"
  85. If ($posted_on == $today_date) {
  86. $datefield = "Today";
  87. $datefield = $datefield . ", " . date($timedisplay, $post[last_post]);
  88. }
  89.  
  90. // If it was posted yesterday, we want to display "Yesterday, hh:mm AMPM"
  91. elseif (date('d F Y',strtotime("-1 day")) == $posted_on) {
  92. $datefield = "Yesterday";
  93. $datefield = $datefield . ", " . date($timedisplay, $post[last_post]);
  94. }
  95.  
  96. else {
  97. $datefield = $today_date;
  98. }
  99.  
  100. /////////////////
  101. // Post Format //
  102. /////////////////
  103. // Between the EOD markers you can put whatever you want in HTML format. Just ensure that the link stays somewhat the same.
  104. <<<EOD
  105.  
  106. <a href="$INFO[board_url]/index.php?showtopic=$post[tid]&view=getnewpost">$post[short_title]</a> by 
  107. <a href="$INFO[board_url]/index.php?showuser=$post[last_poster_id]">$post[last_poster_name]</a> <BR>
  108. $datefield, with $post[posts] replies.<P>
  109.  
  110. EOD;
  111. }
  112.  
  113. ?>
nospor
Przenosze z php Poczatkujacy na Skrypty Forum
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.