How to split articles and show its parts in a dropdown box

Frequently Asked Questions (read only)

How to split articles and show its parts in a dropdown box

Postby FI-DD » Mon Jan 09, 2006 12:47 am

As you know you can split an article into different pages using <!--nextpage-->.



With this little hack you can give each page a description, show these descriptions in a dropdown box and jump to the different pages with the help of this dropdown box.



Instructions:



1. Open inc/show.news.php and find this:

Code: Select all
         $page_count    = sizeof($row['full']);

         $row['full'] = $row['full'][($page ? ($page - 1) : 0)];




replace with this:

Code: Select all
         $page_count  = sizeof($row['full']);

         

         //Start dropdown

         for($k=1; $k < $page_count + 1; $k++) {

            $page_titles[] = explode('<!--nexttitle-->', $row['full'][$k]);

         }

         $first_page = explode('<!--firstpage-->', $row['full'][0]);

         $next_titles = explode('<!--nexttitle-->', $row['full'][$page-1]);

         if($page_count > 1) {

            $output = str_replace('[dropdown-header]', '', $output);

            $output = str_replace('[/dropdown-header]', '', $output);

            $dropdown = '<select onchange="window.location=this.options[this.selectedIndex].value">';

            $dropdown .= '<option value="?page=1"'.($page == 1 ? 'selected' : '').'>'.$first_page[0].'</option>';

            for($j=2; $j < $page_count + 1; $j++) {

               $dropdown .= '<option value="?page='.$j.'"'.($j == $page ? 'selected' :



'').'>'.$page_titles[$j - 2][0].'</option>';

            }

            $dropdown .= '</select>';

         }

         else {

            $dropdown = '';

            $output = preg_replace('/\[dropdown-header\](.*?)\[\/dropdown-header\]/i', '', $output);

         }

         $output = str_replace('{pages-dropdown}', $dropdown, $output);

         //End dropdown



           $row['full'] = $row['full'][($page ? ($page - 1) : 0)];



      //Start dropdown

      $row['full'] = str_replace($first_page[0].'<!--firstpage-->{nl}', '', $row['full']);

      $row['full'] = str_replace($next_titles[0].'<!--nexttitle-->{nl}', '', $row['full']);

      //End dropdown





2. In your full story template add something like this:

Code: Select all
[dropdown-header]Other parts of this article: {pages-dropdown}[/dropdown-header]




3. In the full story of your article put something like this (Put each of the commands on a new line):

Introduction<!--firstpage-->

This is the first page of the article. We call it "Introduction".

<!--nextpage-->Internet<!--nexttitle-->

This is the second page of the article. We call it "Internet".

<!--nextpage-->Computer<!--nexttitle-->

This is the third page of the article. We call it "Computer".

<!--nextpage-->Keyboard<!--nexttitle-->

This is the last page of the article. We call it "Keyboard".
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Return to FAQ



Who is online

Users browsing this forum: No registered users and 0 guests