Hello,
I have specific templates in my theme, which I attach to different kinds of pages. In particular, I attach a specific template to the questions archive (list of questions) and question form (ask a question). I can do that through the WP backend since these are regular pages.
However, when I click on a category, it goes to the questions category archive. The problem is that this category archive uses the default template which is not the one I want. I need to attach a specific template to this page also (and same story for the questions tags archive).
So my question is: how could I specify a specific template to be used for the questions category/tag taxonomy archives? I tried to create a template file in my theme folder named “taxonomy-dwqa-question_category.php” but it doesn’t change anything: the default template file is still applied to the question category archive. I tried to move it to the dwqa-templates subdirectory in my theme folder and it still doesn’t work.
Thanks for advice,
Yves.
Hi Yves Peynaud,
Because page.php
is default page template of DW Q&A.
So, to create a specific template, you can create a Page Template and go to Dashboard > Pages > DW Q&A Page and select page template for this page.
Regards,
Kevin.
I don’t understand. As I tried to explain, I am not speaking about the questions list archive not about the ask a question page, on both of which I am able to select the specific templates I want. I am speaking about the Category archive and Tag archive, which are not regular pages that I could select in the Dashboard > Pages list.
Following the WordPress rules for templates, I have created a “taxonomy-dwqa-question_category.php” file in the root folder of my theme but it seems that DWQA does not use it since there is no difference. Could it be because I use a Child Theme?
Thanks for your help,
Yves.
Hi Yves Peynaud,
You can go to wp-content/plugins/dw-question-answer/inc/Template.php
at line 851 and change this code return dwqa_get_template( $page_template );
to the template you want.
For example: return dwqa_get_template( 'taxonomy-dwqa-question_category.php' );
Regards,
Kevin.
Thanks Kevin for the tip, but it doesn’t work better. Nothing changes.
Actually I use DWQA Pro, so the line isn’t exactly line 851. But I understood what you said just the same.
However your current code should work: as far as I understand, for categories and tags, you pick the same template as the one chosen for the question-list archive. Since I have configured it, it should work. But it doesn’t.
So what is the issue? I have noted that at line 813 of Template.php, you get the theme template directory with: $template_folder = trailingslashit( get_template_directory() ). You might prefer using $template_folder = trailingslashit( get_stylesheet_directory() ); instead to have it working with Child Theme, as it is my case. But it is not the issue since you do not use this $template_folder variable afterwards.
So I really have no idea why it is not working. I am pretty stuck on this. Do you have any other advice for me?
Thanks for you support, I really appreciate it.
Yves.
Hello again,
I have investigated further and I have found the bug: all is correct inside the ‘question_content()’ function of Template.php. What is wrong is the ‘dwqa_get_template()’ function. You test if the template exists with the ‘get_template_directory()’ function. You should systematically use ‘get_stylesheet_directory()’ to make it working with child themes.
As a workaround for now, I have added my template file inside my parent theme. But the next time I update my parent theme or forget to update my template file in both my child theme and parent theme, it will be broken again. You may want to correct it in a next release. Please keep me posted then.
Thanks,
Yves.
I also have this problem and issue. Changing it in the parent directory is something we should not do. Can we get a solution for this, please?
At the moment, the plugin does not support changing the template from the setting or an extra code, you can edit from the plugin core then back up this file.
As I suggested 4 years ago, wouldn’t using ‘get_stylesheet_directory()’ instead of ‘get_template_directory()’ in your code could solve this issue?
@Dominic, can you check @Yves’s message, please? This is almost a crucial fix, as editing the CORE does not make sense and makes it vulnerable. Can we please take a look at this and release it?
Please login or Register to submit your answer