• Hi,
    I was expecting this to be relatively straight forward but am struggling. I wish to set up an FAQ page which lists the questions as links – later I’d like the FAQ searchable, but for now, I’d just like to display the FAQs.

    To facilitate this, I’ve created a category FAQ and am creating several posts assigned to this category – I just need to work out how to display each post as a link on the FAQ page and of course populate the links to take the user to the FAQ text.

    Can anyone advise on how best to go about this?

    thanks

    Matt

Viewing 4 replies - 1 through 4 (of 4 total)
  • You will need to initiate a custom query. You should make a new template page and replace the existing Loop with something like this:

    <?php if ( have_posts() ) : ?>
       <?php $faqsquery = new WP_Query(); ?>
       <?php $faqsquery->query('category_name=faq'); ?>
       <?php while($faqsquery->have_posts()) : $faqsquery->the_post(); ?>
          <div id="post-<?php the_ID(); ?>">
             <h1 class="entry-title">
                <a href="<?php the_permalink(); ?>">
                   <?php the_title(); ?>
                </a>
             </h1>
          </div>
       <?php endwhile; ?>
    <?php endif; ?>

    Hope that helps

    Peter

    Thread Starter mamikel

    (@mamikel)

    Great, thanks Peter. All displaying fine and the link works and takes me to the FAQ post. Just one more thing, when I click on an FAQ, the single.php template is used to render the FAQ post – naturally, I don’t want the title to say News & Events as it does currently. How might I hide the title and instead put in a link back to the FAQ page? i.e. how do I test that I’m here as a result of the user clicking on a category?

    ` <?php if (category=’faq’):?>
    //insert link back to faq??
    <h4 >
    <a href=”javascript:history.back();”>
    Back to FAQ
    </a>
    </h4>
    <?php else:?>
    <div id=”page-title”>
    <div id=”page-title-inner”>
    <div class=”title”>
    <h1>
    News & Events
    </h1>
    </div>
    </div>
    </div>
    <?php endif;?>`

    Make a new template for displaying only faqs. Copy the single.php and call it single-faq.php. This works for any category, tag, custom post type, taxonomy, etc. – WordPress will automatically use that file instead of the usual single.php

    BTW, best not to use history.back() to go back to your list of FAQs – what if someone should bookmark the page and come back to it later? Best to link directly to the URL of the page.

    Happy to have helped

    Peter

    Thread Starter mamikel

    (@mamikel)

    ah ok I see, thanks very much again Peter

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display Post headers from in Category In a Page as links’ is closed to new replies.