Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7706291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:05:20+00:00 2026-06-01T00:05:20+00:00

I’ve searched everywhere and can’t find a solution to this: I’m developing a WordPress

  • 0

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 ); ?>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:05:21+00:00Added an answer on June 1, 2026 at 12:05 am

    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 🙂

    <?php // show mobile comments 
    comments_template( '/mobile-comments.php', true ); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.