Support » Fixing WordPress » Unexpected T_CONSTANT_ENCAPSED_STRING on single.php

  • Hello. I’m trying to test my blog, but run into problems when viewing individual test posts or trying to post test comments. On single.php, I get this error:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/indulgealunatic/ on line 25

    Line 25 is simply this:

    <?php previous_post_link('%link') ?> <?php next_post_link('%link') ?>

    I’ve removed some superfluous things from the line to reduce it down to this, and I’ve checked the line multiple times, but I continue to receive this error. I looked the error up on Google and it said it often comes from not having semicolons closing a piece of code, so I tried putting in semicolons after the closing parenthesis but I got the same error. I’ve tried everything I can think of in terms of playing with small things in the line, and I don’t know what else to do.

    The site is and you can see the error when you click on the post title links or the “no comments” links.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You need to have the semicolons after the “)”. Must have it in both cases. Also, make sure there is a space between the semicolon and the closing question mark.

    Why do you have this code on a single post? There is no previous or next. You only need a previous or next link for a collection of posts, not a single one.

    The idea of having the post links is so that you can go from one single post to another single post.

    However, as I mentioned in my original post, when I add semicolons after each closing parenthesis and still get this error. And there are spaces between the semicolons and the question marks. I tried adding the semicolons again, and the error still shows up.

    I see. Okay let’s try this…

    All php statements must end with the semicolon. So, make sure the semicolons end each of these 2 statements. Then look in the lines above these statements for another statement that is missing the semicolon.

    It’s likely that if this mistake exist once in this file, it exists elsewhere in the file as well.

    As a test, I added your code to my single.php page (without semicolon); it worked fine. But it was the last line of code on the page. When I moved this line of code above another php statement though, the code failed.

    When I added the semicolon, everything worked again. It is just a quick test but it did prove the lack of the semicolons will cause problems.

    I read through single.php and I found this line:

    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>

    I changed the colons to semicolons and removed the spaces, but it still didn’t work.

    This is the relevant coding in single.php; maybe I’m missing something.

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <div id="container">
    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <div class="post">
    <a href="<?php the_permalink(); ?>" title=”<?php the_title(); ?>”><?php the_title(); ?></a>
    <div class="entry">
    <?php the_content(); ?>
    <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
    <p class="postmetadata">
    Filed under: <?php the_category(); ?> by <?php the_author(); ?> <?php edit_post_link('Edit', ' | ', '); ?>
    <div class=”comments-template”>
    <?php comments_template(); ?>
    <?php endwhile; ?>
    <div class="navigation">
    <?php previous_post_link('%link'); ?> <?php next_post_link('%link'); ?>
    <?php else : ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php ('Not Found'); ?></h2>
    <?php endif; ?>

    Thanks for all of your help so far. 🙂

    No, you don’t want to do that! This portion of code is using the alternate php syntax.

    Let me take a look here … brb

    This section of code is wrong. There should be a closing single quote.

    <?php edit_post_link(‘Edit’, ‘ | ‘, ‘); ?>
    Edit is wrapped in single quotes, followed by a comma …
    Space Post Space is wrapped by single quotes, followed by a comma …
    Then there is a single quote. There should be 2 single quotes and probably somethin between them.

    I removed everything after Edit and its single closing quote and it’s now working.
    I don’t know what the | was supposed to be for, as I got help with the single.php coding from a tutorial. Thank you for pointing that out for me, and thank you for all of your help! 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Unexpected T_CONSTANT_ENCAPSED_STRING on single.php’ is closed to new replies.