Please or Register to create posts and topics.

wpdb display of the latest topics on pages other than the forum !

Hello,

Attention it is necessary to know a minimum the code for that, nevertheless the codes are ready to copy and paste to you to adapt the design, these codes can be applied anywhere on your site as long as the plugin is activated...

 

For show the last 5 topics or 5 posts, (copie the following code in your theme).

 

Change the value (LIMIT 0,?)  to increase or decrease the number of displays,

the first digit represents which value you want to apply the code for example 0.5 will take all inputs from the beginning to a maximum of 5.

If you do 2.10 it will take from input 2 to 10 post/topic but will start from post 2.

<?php 
                //Show the last 5 topics 
                $sql = "SELECT name FROM {$wpdb->prefix}forum_topics ORDER BY ID DESC LIMIT 0,5";
                $result = $wpdb->get_results($sql) or die(mysql_error());

                foreach( $result as $results ) {

                    echo "Topic : " , $results->name , '</br>';
                }
?>
<?php 
                //Show the last 5 posts with date
                $sql = "SELECT text, date, DATE_FORMAT(date, '%d/%m/%Y - %Hh%i') AS date FROM {$wpdb->prefix}forum_posts ORDER BY ID DESC LIMIT 0,5";
                $result = $wpdb->get_results($sql) or die(mysql_error());

                foreach( $result as $results ) {

                    echo  $results->text , '</br>';
                    echo  "<b>Date : ", $results->date , '</b></br>';
                }
  ?>
<?php 
              //Show 5 topics and numbers of view topic !
              $sql = "SELECT name, views FROM {$wpdb->prefix}forum_topics ORDER BY ID DESC LIMIT 0,5";
              $result = $wpdb->get_results($sql) or die(mysql_error());

              foreach( $result as $results ) {

                  echo "Topic : " , $results->name , '</br>';
                  echo "Views : " , $results->views , '</br>';
              }
              ?>

 

Others examples with bootstrap 4x :

<div class="col-lg-6">   
           <div class="module">
               <div class="moduletitre">Asgaros Forum ( Max 5 Topics ) Views/link/name</div>
               <?php 
               //
               $sql = "SELECT name, views,id FROM {$wpdb->prefix}forum_topics ORDER BY ID DESC LIMIT 0,5";
               $result = $wpdb->get_results($sql) or die(mysql_error());

               foreach( $result as $results ) {

                   echo "Topic : " , $results->name , '</br>';
                   echo "Views : " , $results->views , '</br>';
                   echo "Slug : <a href=http://localhost/themename/forum/?view=topic&id=" , $results->id , '>Link</a></br></br></br>';
               }
               ?>
           </div>
       </div>    



       <div class="col-lg-6">   
           <div class="module">
               <div class="moduletitre">Posts Asgaros Forum ( 5 Max Post ) Content/link/date </div>
               <?php 
               //
               $sql = "SELECT text, date, id, DATE_FORMAT(date, '%d/%m/%Y - %Hh%i') AS date FROM {$wpdb->prefix}forum_posts ORDER BY ID DESC LIMIT 0,5";
               $result = $wpdb->get_results($sql) or die(mysql_error());

               foreach( $result as $results ) {

                   echo  $results->text , '</br><br>';
                   echo  "<b>Date : ", $results->date , '</b></br><br>';
                   echo "Slug : <a href=http://localhost/themename/forum/?view=topic&id=" , $results->id , '>Link</a></br></br></br>';


               }
               ?>
           </div>
       </div>

 

 

View :

Follow me on Twitter

Uploaded files:
  • screencapture-localhost-cryogames-devapi-2019-02-17-18_11_21.jpg
Asgaros, Yworld and 2 other users have reacted to this post.
AsgarosYworldYeyeShepXBFR