SSI FAQ Advanced From Online Manual

Jump to: navigation, search

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.

PLEASE DO NOT EDIT YOUR 'SSI.PHP' FILE

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 certain 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 probably think this is impossible to achieve and need [Unknown] to help you write this code, but no, you can do this in minutes very easily, and I will explain how.

You are probaly used to displaying a function on a page like so: 'functionName();' but if you want to configure the function, you must send along some parameters 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 parameters 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


<?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, you have exactly what you wanted.

Most of the functions in 'SSI.php' work with parameters 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.

  1. The function is named and opened.
  2. We connect to the MySQL databse.
  3. We extract the information we need for the function.
  4. We put the information extracted in variables and arrays.
  5. 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 all. Lets 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 except 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



Advertisement: