Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frequently Asked Questions (FAQ) Plugin
#17
wirehack7 Wrote:A very, very special thanks! You helped me out.
Next is: how I show questions first as anchor links and then each question with answer? :X

Hi,

You can change the getFAQData function in faq.php with this one :
or add it with another name, read post 19
(NB. I added <span class="faqC">, </span> and other class="faqQ" class="faqA" for use in CSS, you can erase them in the function)

Code:
function getFAQData($display_category=null,$display_faq=null)
{
    $data_file = getXML(FAQFile);
    $end_result = '';
    foreach($data_file->category as $category)
    {
        $c_atts= $category->attributes();
        if($display_category == null)
        {
            $end_result .= '<ul><li><span class="faqC">'.$c_atts['name'].'</span><ul>';
            
            foreach($category->content as $content)
            {
                $atts = $content->attributes();
                $end_result .= '<li><a class="faqQ" href="?id=faq&display_category='.urlencode($c_atts['name']).'&display_faq='.urlencode($atts['title']).'">'.$atts['title'].'</a></li>';
            }
            $end_result .= '</ul></li></ul>';
        }
        elseif($display_category == $c_atts['name'])
        {
            $end_result .= '<ul><li><span class="faqC">'.$c_atts['name'].'</span><ul>';
            foreach($category->content as $content)
            {
                $atts = $content->attributes();
                if($display_faq == null)
                {
                    $end_result .= '<li><a class="faqQ" href="?id=faq&display_category='.urlencode($c_atts['name']).'&display_faq='.urlencode($atts['title']).'">'.$atts['title'].'</a></li>';
                }
                elseif($display_faq == $atts['title'])
                {
                    $end_result .= '<li class="faqQ">'.$atts['title'].'<ul><li class="faqA">'.$content.'</li></ul></li>';
                }
            }
            $end_result .= '</ul></li></ul>';
        }
    }
    return $end_result;
}

You need to modify getFAQ too for :
or add it with another name, read post 19
Code:
function getFAQ($display_category=null,$display_faq=null)
{
    echo getFAQData($display_category,$display_faq);
}

and you can test it in a template with :
Code:
<style>
.faqC { color:magenta; }
.faqQ { color:purple; }
.faqA { color:grey; }
</style>
    <div class="wrapper clearfix">
        <!-- page content -->
        <article>
            <section>
                
                <!-- title and content -->
                <?php
                    if ($_GET && isset($_GET["display_category"]))
                    {
                        if (isset($_GET["display_faq"]))
                        {
                            getFAQ($_GET["display_category"], $_GET["display_faq"]);
                        }
                        else
                        {
                            getFAQ($_GET["display_category"]);
                        }
                    }
                    else {
                        getFAQ(); /* all categories and Q/A */ ?> <hr />
                        <?php getFAQ("Catégorie de test"); /* the category "Catégorie de test" */ ?> <hr />
                        <?php getFAQ('Tests v2', null); /* the category "Tests v2" same as above */ ?> <hr />
                        <?php getFAQ('Tests v2', 'test 02'); /* the category "Tests v2", question "test 02" */ ?>
                <?php
                    }
                 ?>
            </section>        
        </article>


It was for testing the different results, in real you would prefer in your template :
again, use it with another name, read post 19
(and if you keep the css part, it' better in the theme .css)
Code:
<?php
if ($_GET && isset($_GET["display_category"]))
{
    if (isset($_GET["display_faq"]))
    {
        getFAQ($_GET["display_category"], $_GET["display_faq"]);
    }
    else
    {
        getFAQ($_GET["display_category"]);
    }
}
else {
    // put here your default display fonction, i.e.
    getFAQ();
}
?>
Reply


Messages In This Thread
Frequently Asked Questions (FAQ) Plugin - by Wos - 2012-04-27, 23:52:34
Frequently Asked Questions (FAQ) Plugin - by Wos - 2012-04-28, 06:29:55
Frequently Asked Questions (FAQ) Plugin - by Wos - 2012-04-29, 16:33:52



Users browsing this thread: 2 Guest(s)