No edit summary |
No edit summary |
||
Line 145: | Line 145: | ||
---- | ---- | ||
Well this pretty much covers the advanced Guide, the next guide will be: 'Expert SSI FAQ'. | Well this pretty much covers the advanced Guide, the next guide will be: '[[SSI_FAQ_Expert|Expert SSI FAQ]]'. | ||
Revision as of 14:36, 7 June 2013
Advanced SSI FAQ
Hello and welcome to the Advanced SSI FAQ, in this FAQ you will learn the more advanced uses of SSI, this FAQ is written assuming you have already read the 'Basic SSI FAQ'. This FAQ has commonly asked SSI questions as well as tips and tricks, you will also find a list of attached scripts to the end of this post that may help you with what you have learned in this FAQ. If at the end you still have questions or comments, please post them. Your feedback if very imporant to me.
PLEASE DO NOT EDIT YOUR 'SSI.PHP' FIL Everything done here is done without having to edit 'SSI.php'
How Can I Edit Functions for my Needs?
A common question, if you can edit functions to fit your specific needs, and the answer is, [color=Green]EASILY![/color] Lets take an example to help us out:
Example:
You have a site, and also a forum, and on your main page you are using the ssi functions, 'ssi_boardNews' which displays the first post from threads in a ceratin board from your forum onto the page, you want to configure the function so that it only takes the first post of the thread from a certain board [Your announcements board], and that it wont display more then 5 threads so your page wont be too long, you also want that if the post is too long it will shorten it to save room, lets say, 250 characters long.
So most of would probaly think this is impossible to achieve and need [Unknown] to help you write this code, but no, you can do this in minutes very eaily, and I will explain how.
You are probaly used to displaying a function on a page like so: '[i]functionName();[/i]' but if you want to configure the function, you must send along some paramters along with the function. This specific function, 'ssi_boardNews' takes the following parameters:
<?php ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo'); ?> }} All you need to do is to change these paramters to your needs, and in our case, change them like this: ''Assuming board 5.0 is the board you want to take the posts from'' {{code|1=<nowiki> <?php ssi_boardNews($board = 5.0, $limit = 5, $start = null, $length = 250, $output_method = 'echo'); ?>
And that is the code you need to write in your page to get it working.
- $board = 5.0 - It takes the first post of the thread from board with the ID of 5.0
- $limit = 5 - Limits the number of posts to take to 5. (It will take the 5 newest ones)
- $start = null - You can leave this as is.
- $length = 250 - Limits the number of characters per post to 250.
- $output_method = 'echo' - You can leave this as is.
Copy that code into your main page, and walla, you have exactly what you wanted.
Most of the functions in 'SSI.php' work with paramters that can be easily modified as so.
How is a function built?
Please dont skip this part as in is vital knowing to answer the future questions.
The functions in 'SSI.php' are built like so:
Dont feel bad if you dont understand all of this.
- The function is named and opened.
- We connect to the MySQL databse.
- We extract the information we need for the function.
- We put the information extracted in variables and arrays.
- We display the information.
This information will help us in the next question, 'How Can I Only Display a Certain Part of a Function?'.
How Can I Only Display a Certain Part of a Function?
Another common question, how do I only display a certain part of a function? This is very easily done without the need of editing 'SSI.php' at allLets take an example to help us out, I will use the same function as before, 'ssi_boardNews'
Example:
I have the function 'ssi_boardNews' displayed on my main page of my site using SSI, I only want to display the title of the thread and the body of the message, no fancy little icons and dates.
Now that we know how a function is built, modifying it for out needs is easy. This is part of the 'ssi_boardNews' function, the part that displays the information.
foreach ($return as $news) { echo ' <table border="0" width="100%" align="center" class="ssi_table"> <tr> <td>', $news['icon'], ' <b>', $news['subject'], '</b><span class="smaller"><br />', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '<br /><br /></span></td> </tr> <tr> <td>', $news['body'], '<br /><br /></td> </tr> <tr> <td>', $news['link'], ' | ', $news['new_comment'], '</td> </tr> </table> <br />'; if (!$news['is_last']) echo ' <hr width="100%" /> <br />'; }
The first section in this part says 'foreach ($return as $news)' meaning for every thread there is it will run the code in between the brackets.
So we need to take everything out exept for the topic name and topic body, this is the code needed to write on a page to display only the thread name and body and also limit the threads from coming only from a special board (board ID=5.0), limits the number to 5 posts, and makes sure every post is no more then 250 characters..Note that the output method has changed.
<?php $array = ssi_boardNews(5.0, 5, null, 250, 'array'); foreach ($array as $news) { echo ' <table border="0" width="100%" align="center" class="ssi_table"> <tr> <td><b>', $news['subject'], '</b></td> </tr> <tr> <td>', $news['body'], '<br /><br /></td> </tr> </table> <br />'; if (!$news['is_last']) echo ' <hr width="100%" /> <br />'; } ?>
That should display only the topic title and body, you can also remove or add some '<br />'s to make it fit! (<br /> makes a new line.)
Most of the functions work along this line, so I hope this helps.
Well this pretty much covers the advanced Guide, the next guide will be: 'Expert SSI FAQ'.
Copied from http://www.simplemachines.org/community/index.php?topic=13016.0