Forums Forums Search & Filter Pro Custom archive page template

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Anonymous
    #184187

    I’ve created a page template that shows categories and then posts within those categories. I’d like to use this template to display Search and Filter results, with the S&F form at the top of the page.

    I’ve tried putting the shortcode from the form in the content of the page that uses the custom template described above. And I’ve tried the Display as Archive technique. Still no form showing.

    Below is the code for the template. Is there any reason this can’t work as a template for displaying S&F results? Thanks.

    <?php
    /* template name: Authors Page Test */
     ?>
    <?php get_header(); ?>
     
    <div id="container">
        <div id="content" role="main">
    
        <?php
        // get all the categories from the database
        $cats = get_categories(); 
    
            // loop through the categries
            foreach ($cats as $cat) {
                // setup the cateogory ID
                $cat_id= $cat->term_id;
                // Make a header for the cateogry
                echo "<h2>".$cat->name."</h2>";            // create a custom wordpress query
                query_posts("cat=$cat_id&posts_per_page=100");
                // start the wordpress loop!
                if (have_posts()) : while (have_posts()) : the_post(); ?>
    
                    <?php // create our link now that the post is setup ?>
                    <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
                    <img name="" src="<?php echo get_the_post_thumbnail_url(); ?>" width="200" alt="">
                    <img src="<?php the_field('featured_book_cover_image'); ?>" class="featured_title_cover_image" width="100" height="150" />
                    <?php the_field('featured_book_title'); ?>
                    <?php echo '<hr/>'; ?>
    
                <?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
            <?php } // done the foreach statement ?>
    
        </div><!-- #content -->
    </div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    Trevor
    #184208

    I do not see the do_shortcode needed to output the form?

    The issue with the approach that you have here is what happens if a post has more than one category attached?

    Your code appears to be fetching all the categories defined, then finding, for each category, the posts in it. You then output the posts within subsections of categories, thus would duplicate some posts as they would appear in more than one sub-section.

    Our filter arguments would tend to override what you are trying, but you might try it as a Custom display method and add our filter. This is from our documentation:

    If you prefer to use a more standard template (such as one from your theme) then you might want to use query_posts, again pass in the arguments to $args or alternatively you can run our action which makes things a bit easier:

    do_action("search_filter_query_posts", 123);

    The query argument would be:

    'search_filter_id' => 1234

Viewing 2 posts - 1 through 2 (of 2 total)