Hi,
I use the Event Calendar plugin with the post type = “tribe_events” that is also successfully recognized in CPT & Taxonomy from your theme. I also use a child theme in which I copied the page.php (that is used from the Event Calendar plugin to list the events).
Now I want that the comment_template is always displayed in the page.php (of my child theme) when the post type = “tribe-events”. Because the comments can only be enabled / disabled in the Theme Panel for ALL pages without any exceptions.
Therefore I made some amendments in the page.php that worked pretty well – the post type is recognized successfully and the comments are always shown, when the post type = tribe events. When the post type is not tribe events the comments template is not shown 🙂 The disadvantage of this is, that in case I want to use the comments on another page in future, it won’t work properly without making changes to the code. Because I disabled the settings in Theme Panel with my amendments.
So I tried to enhance my code a little bit to show the comments always for post type = “tribe events” AND to make the settings in the theme panel still work.
(...)
<div class="td-page-header">
<h1 class="entry-title td-page-title">
<span><?php the_title() ?></span>
</h1>
</div>
<div class="td-page-content">
<?php
the_content();
// check if post type is tribe-events
if (get_post_type() == 'tribe_events' ) {
echo 'Yes, post type is tribe events <br />';
$checkcomment = comments_template('', true); //show comments
// when post type NOT tribe events, check what is set in Theme Panel
} else {
echo 'Nope, post type is not tribe events <br />';
$td_enable_or_disable_page_comments = td_util::get_option('tds_disable_comments_pages'); //check settings
// when comments not allowed in Theme Panel settings, don't show comments
if ($td_enable_or_disable_page_comments != 'show_comments') {
echo 'Sorry, comments are not allowed for pages';
$checkcomment = comments_template('', false);
// when comments are allowed in Theme Panel settings, show comments
} else {
echo 'Great, comments are allowed for pages';
$checkcomment = comments_template('', true);
}
}
endwhile; //end loop
}
?>
</div>
<?php echo $checkcomment;?>
</div>
(...)
Unfortunately the comments template is not displayed on any other pages (although I enabled it in the Theme Panel settings) than on the one with post type =tribe-events”.
On all pages my “testing texts” from the echos (like “Great, comments are allowed for pages”) are always correct (depending on my settings in the theme panel). So the code seem to work …almost… properly :-/
Could you please help me or give me advice whether I have overseen something?
Many Thanks in advance,
Dinah
Hi,
You will have to keep trying until you get the desired results. Unfortunately I cannot test this on my end, so I cannot provide a surely working solution. Roll back to the code that worked before. Double check the code conditions added and make sure there are no syntax mistakes and the code is written properly (maybe use an online PHP code checker after you are done just to be sure)
Comments for pages are defined in the page templates files as you mention, and the comment section for posts is in the single files
– https://www.screencast.com/t/s39qAeb3
Thanks