I’ve searched everywhere and can’t find a solution to this:
I’m developing a WordPress theme, and am in the process of creating the comments.php file. Here’s my code so far:
On my single.php page, I have at the top <?php $mobile_blog = 'true'; ?>
and then in my comments.php file, I have:
// begin if statement
<?php if($mobile_blog == 'true') : ?>
// If $mobile_blog variable is set to true on the page, show this code.
<div id="comments" class="blog-comments">
<?php if($comments) : ?>
<ol class="comments blog-comments" style="list-style:none;">
<?php wp_list_comments('type=comment&callback=company_mobile_comments'); ?>
</ol>
<?php else : ?>
<p>No comments yet</p>
<?php endif; ?>
</div>
<?php else : ?>
// If $mobile_blog variable is NOT set to true on the page, show this code.
<div id="comments" class="blog-comments"><span class="t">
<?php comments_number( 'No Comments', '1 Comment so far', '% Comments' ); ?>
</span>
<?php if($comments) : ?>
<ol class="comments">
<?php wp_list_comments('type=comment&callback=company_comments'); ?>
</ol>
<?php else : ?>
<p>No comments yet</p>
<?php endif; ?>
</div>
//end of if statement
<?php endif; ?>
What I’m trying to achieve here is that if the page sets the $mobile_blog variable to true, show the top section of code, else if the variable is not set or does not equal true, show the bottom section of code.
For some reason, when I use the code included here, it only shows the bottom section of code even when the variable is set to true. No matter what I do, I can’t seem to get it to show the proper code either way when needed.
EDIT:: Instead, is there a way to have the template pull a different comments.php file depending on if the variable is set to true or not? I include the comments in my single.php page by using <?php comments_template( '', true ); ?>
I actually found a way to pick which comments template for the mobile version of the template to show. The code below lets you pick which comments.php file to use 🙂