|
Posted by Toby Inkster on 11/11/05 22:17
DKsWebboy wrote:
> My question is, was there an easier way of doing that besides have to
> put (and name) anchor points at EACH and EVERY answer and EACH and
> EVERY question (for the "return" link)? Seems like there'd be a way
> to do that quicker...
You can automate much of it with server side scripting...
<?php
function faq_init ()
{
global $faq;
$faq = array();
$faq['h_num'] = 0;
$faq['q_num'] = 1;
}
function faq_heading ($h)
{
global $faq;
$faq['h_num']++;
$faq[] = array(
'n'=>$faq['h_num'],
'heading'=>$h
);
$faq['q_num'] = 1;
}
function faq_question ($q, $a)
{
global $faq;
$faq[] = array(
'n'=>($faq['h_num'] . '.' . $faq['q_num']),
'question'=>$q,
'answer'=>$a
);
$faq['q_num']++;
}
function faq_finalise_index ()
{
global $faq;
$out = "<div id=\"q_idx\">\n"
. " <h1>Frequently Asked Questions</h1>\n";
for ($i=0; isset($faq[$i]); $i++)
{
$f = $faq[$i];
if (isset($f['heading']))
$out .= " <div>\n"
. " <strong>{$f['n']}: {$f['heading']}</strong>\n"
. " <ul>\n";
elseif (isset($f['question']))
$out .= " <li><a href=\"#q_{$f['n']}\">{$f['n']}: "
. "{$f['question']}</a></li>\n";
if (isset($faq[$i+1]['heading'])
|| !isset($faq[$i+1]))
$out .= " </ul>\n"
. " </div>\n";
}
$out .= "</div>\n";
return $out;
}
function faq_finalise_body ()
{
global $faq;
$out = "";
for ($i=0; isset($faq[$i]); $i++)
{
$f = $faq[$i];
if (isset($f['heading']))
$out .= "\n<h2 class=\"secheading\">{$f['n']}: {$f['heading']}</h2>\n";
elseif (isset($f['question']))
$out .= "\n<h3 class=\"question\" id=\"q_{$f['n']}\">{$f['n']}: "
. "{$f['question']}</h3>\n"
. "<div class=\"answer\" id=\"a_{$f['n']}\">{$f['question']}</div>\n"
. "<div class=\"uplink\"><a href=\"#q_idx\">Back to top</a>.</div>\n";
}
return $out;
}
faq_init();
faq_heading("Foo");
faq_question("What is a foo?", "The opposite of a bar.");
faq_question("How can I spell foo?", "F-O-O.");
faq_heading("Bar");
faq_question("What is a bar?", "The opposite of a foo.");
faq_question("How can I spell bar?", "B-A-R.");
faq_question("What can I do with a bar?", "Combine it with a foo.");
print faq_finalise_index();
print faq_finalise_body();
?>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|