WordPress.org

Forums

SP responsive wp-faq with category plugin
[resolved] Display a specific FAQ category archive (14 posts)

  1. rxcknrxll
    Member
    Posted 1 year ago #

    This plugin allows you to categorize your FAQs. But when I try to view a specific category of FAQ, I just land on a page that says "sorry, no content matched your criteria".

    I only see one shortcode for this plugin. Is there a way to display just a single category of FAQ on a page? It seems confusing to me why I would want to categorize FAQs if they can't be viewed that way.

    Any insight is much appreciated!

    http://wordpress.org/plugins/sp-faq/

  2. johndove523
    Member
    Posted 1 year ago #

    Same question. I tried [sp_faq category="general_faqs"] but it does not recognize categories (still gives me all categories). I'm pretty sure this could be fixed in faq.php but I don't know enough .php to fix it.

  3. rxcknrxll
    Member
    Posted 1 year ago #

    I've altered how I use the plugin, so I'm only using it as a single FAQ. It's clearly meant to be able to organize multiple categories, but I can't find a shortcode variation or anything that works either.

  4. J87637746
    Member
    Posted 1 year ago #

    I would also like to know how to show the FAQ from just one category

  5. emanweb
    Member
    Posted 1 year ago #

    I took a look in the code and I don't think this feature is set yet. Perhaps in future releases. I plan coding this myself pretty soon... I keep you guys posted.

  6. emanweb
    Member
    Posted 1 year ago #


  7. cportermalta
    Member
    Posted 1 year ago #

    Hi,

    Did a quick fix to the plugin to show specific cats via the shortcode (using the category ID).

    1) Open up the faq.php script

    2) Find function sp_faq_shortcode()

    3) Add the cat => '' in the first line, as shown below:

    extract(shortcode_atts(array(
      "limit" => '',
      "cat" => ''
    ), $atts));

    4) Add the //Define Category block just below the //Define Limit block, as shown below:

    // Define category
      if( $cat) {
        $category_id = $cat;
      } else {
        $category_id = '-1';
      }

    5) Finally, replace the query bit with this:

    $query = new WP_Query( array (
       'post_type'      => $post_type,
       'posts_per_page' => $posts_per_page,
       'cat'            => $category_id,
       'orderby'        => $orderby,
       'order'          => $order,
       'no_found_rows'  => 1,
      )
    );

    6) Use with this shortcode: [sp_faq limit="-1" cat="XX"] where XX is the category ID (if you don't know where this is, open up the list of categories, click on the desired category, and check the tag_ID=XX in the URL).

    7) Get a cup of coffee and enjoy :)

    Disclaimer: I hacked this up simply because I needed a quick fix... the plugin's author might have something else in store, and updates will obviously break this fix. However, it works.

    Chris

  8. amazemedia
    Member
    Posted 1 year ago #

    Chris, awesome hack! Thank you.

    Any thoughts on why it only works for 1 category on a page? I need to be able to display multiple catergories on a page so we can break things up by topic.

  9. cportermalta
    Member
    Posted 1 year ago #

    Cheers :)

    Well, I tried adding another short-code with another cat ID, and although the FAQs are loaded, they are not picked up by the script and are left unformatted/static. It's an issue with jquery picking up the element using an ID (thus, two elements with the same ID will break the logic)

    So, another quick hack :)

    In faq.php, find this line:
    <div id="accordion">
    and change it to:
    <div class="accordion">

    This will make it possible to select multiple elements using the class selector rather than the id jquery selector.

    Now...

    Replace this line:
    jQuery( "#accordion" ).accordion({

    with:
    jQuery( ".accordion" ).accordion({

    ... indicating that you want to initialize all the divs decorated with the class "accordion" hence the . instead of the # (indicating an id attribute).

    This might work. Haven't tested it for exceptions, however it does the trick (at face value).

    Chris

  10. amazemedia
    Member
    Posted 1 year ago #

    Very much appreciate your efforts! Did your handy hacks but did not work.

    If I drop {heightStyle: "content"} than it works but the first Q of each category is expanded.

    http://www.closetcollabo.ca/faq2/

  11. cportermalta
    Member
    Posted 1 year ago #

    Hi there,

    In that case you need to modify the way the accordion is initialized (collapsed property):

    You need to modify this line in faq.php:

    jQuery( ".accordion" ).accordion()

    ... on the lines indicated in this SO article here.

    Hope this helps!

    Regards,

    Chris

  12. amazemedia
    Member
    Posted 1 year ago #

    Thank you so much! You saved me hours I'm sure!

  13. jkdesign82
    Member
    Posted 1 year ago #

    Thank You!

  14. janshkin
    Member
    Posted 1 year ago #

    This works like a charm, amazing work, thanks a million for sharing! You helped me fix my site in under 15 minutes!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic