0

Im developing a "catalogue" plugin using a custom post type and a custom taxonomy. What I want now is to display the custom taxonomy as a single page. That means I if the taxonomy term "Popular Items" is requested I want to query all posts for this category, render and buffer my own template (phtml) including all posts belonging to that taxonomy term as a table. This buffered table should be rendered using the default single template file from the theme. So without any pagination or multiple posts at one page.

I tried to customize the WP_Query and generate a new one inside the pre_get_posts action but got no results emulating a single post query with my own content.

add_action("pre_get_posts", array( $this, 'check_for_iccat' ) );
...
public function check_for_iccat( $query ) {
    if( is_tax( 'iccat' ) ) {
        $termId = get_queried_object()->term_id;
        echo "<pre>"; print_r ($query); echo "</pre>";
        exit(); // debug view 
    }
}

Another idea is to create a second post-type injecting the rendered category buffer and displaying as page.

Any suggestions how I can do this?

Update: Another way to achieve this is to save the rendered category output into the database and provide a shorttag like [category=popular]. This tag can be used inside a normal page or post. Before the post / page is rendered I can replace it with the pre rendered and cached content. Is that the only solution? I'm looking for a more automatic solution.

Thanks in Advance!

4
  • 4
    What about forcing a custom taxonomy template (taxonomy-{taxonomy-slug}.php) with your desired single.php design/look? Jan 27, 2015 at 14:39
  • 1
    Are you going to use the taxonomy archive as well (e.g. is the taxonomy public)? Or are you wanting to basically have a custom template for the term archive for this taxonomy? If the latter, what Mayeenul Islam said would be a solid way to go.
    – Privateer
    Jan 27, 2015 at 14:40
  • The taxonomy archive should not be used. The problem using a special taxonomy template is, that the user has to provide such a template within his theme. Of course I can redirect to a fallback template within my plugin. But I don't know how the theme is built and the fallback template will break the themes design. So I'm looking for a more automatic way injecting the content into the theme. Jan 27, 2015 at 14:45
  • 2
    If you are worried about using taxonomy template because the user has to provide the template within the theme, you should be worried about using single template also because single.php is not a required template file for a theme and it can or can not exists in the theme. You should think again about what you are trying to do and how you should do it. From my point of view you should provide a template fallback in your plugin and leave the door open for themes to override the output and design if they want.
    – cybmeta
    Jan 27, 2015 at 15:27

1 Answer 1

0

Considering the comments and wasting a few more hours searching for a solution I came to the conclusion I have to review my plugin design. There are two promising approaches:

  1. Using a template file and provide a fallback.
  2. Providing a "shorttag" generator and make the user to create a post / page for each needed category.

Thanks for your participation and help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.