• I keep getting

    Parse error: syntax error, unexpected ‘<‘ in wpcaluwild/wp-content/themes/CalUWildTheme/sidebar3.php on line 20, that reads <?php query_posts(‘showposts=1’); ?>

    .

    Here’s all the code:

    <div id="sidebar3">
        <div id="nav">
    
    <ul>
    		  <?php wp_list_pages("title_li=&exclude=12,16,23,339");?>
    		</ul>
    	</div>
    	<?php if (is_single()) {
    	echo "<h2>Past Newsletters</h2>";
    	wp_get_archives('type=postbypost');
    	}
    	elseif (is_page('home')) {
    		echo "<h2>Latest Newsletter</h2>";
    		<?php query_posts('showposts=1'); ?>
    		<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><a>"><?php the_title(); ?></a></h2>
    			<p><?php the_time('F jS, Y') ?> </p>
    			<?php the_excerpt(); ?>
    		</div>
    
    	<?php endwhile; ?>
    
    	}
    	elseif
    		(is_page('membership')) {
    		echo "<h2>Membership Form</h2>";
    		echo "<a href='https://www.mywebsite.com/wpcaluwild/?page_id=16'>Please take a minute to join us by filling out our membership form.</a>";
    		}
    	}?>
    </div>

    All curly braces and brackets are matched as far as I can see, which according to PHP help is the primary reason for this error message.

    Thanks in advance for the answer!
    Michael

Viewing 10 replies - 1 through 10 (of 10 total)
  • you have <?php tags while you’re already in your php. your code

    elseif (is_page('home')) {
    		echo "<h2>Latest Newsletter</h2>";
    		<?php query_posts('showposts=1'); ?>

    would have to be closed out after the echo … in order for you to be able to use the <?php tag again, two solutions:

    elseif (is_page('home')) {
    		echo "<h2>Latest Newsletter</h2>";
    ?>
    		<?php query_posts('showposts=1'); ?>
    ...

    or

    elseif (is_page('home')) {
    		echo "<h2>Latest Newsletter</h2>";
    		query_posts('showposts=1');
    ...

    Thread Starter mjkane

    (@mjkane)

    Okay many thanks for the advice. But now I have spent an hour with this issue,Parse error: syntax error, unexpected $end in line 39 that is the closing div </div>.

    Again here’s all the code:

    <div id="sidebar3">
        	<div id="nav">
    		<ul>
    		  <?php wp_list_pages("title_li=&exclude=12,16,23,339");?>
    		</ul>
    	</div>
    	<?php if (is_single()) {
    	echo "<h2>Past Newsletters</h2>";
    	wp_get_archives('type=postbypost');
    	}
    	elseif (is_page('home')) {
    		echo "<h2>Latest Newsletter</h2>"; ?>
    		<?php query_posts('showposts=1'); ?>
    		<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><a>"<?php the_title(); ?>"</a></h2>
    			<p><?php the_time('F jS, Y') ?> </p>
    			<?php the_excerpt(); ?>
    		</div>
    
    	<?php endwhile; ?>
    	}
    
    	elseif
    		(is_page('membership')) {
    		echo "<h2>Membership Form</h2>";
    		echo "<a href='https://www.michaeljkane.com/wpcaluwild/?page_id=16'>Please take a minute to join us by filling out our membership form.</a>";
    		}
    		<?php endif; ?>
    		</div>

    I double checked for “empty” spaces but I can’t seem to shake the unexpected $end error.

    Oh before I forget many thanks to simplistik for the very fast response earlier.

    You have this:

    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><a>"<?php the_title(); ?>"</a></h2>
    			<p><?php the_time('F jS, Y') ?> </p>
    			<?php the_excerpt(); ?>
    		</div>
    
    	<?php endwhile; ?>

    Which includes an “if have posts” and a “while have posts” but at the end you only end the “while” statement, but not the if. Try this:

    <?php endwhile; ?><?php endif; ?>

    Thread Starter mjkane

    (@mjkane)

    Still a no go. Made the changes adding <?php endwhile; ?> and <?php endif; ?> statements, yielding the same parse error, unexpected $end;

    <div id="sidebar3">
        	<div id="nav">
    
    <ul>
    		  <?php wp_list_pages("title_li=&exclude=12,16,23,339");?>
    		</ul>
    	</div>
    	<?php if (is_single()) {
    	echo "<h2>Past Newsletters</h2>";
    	wp_get_archives('type=postbypost');
    	}
    	elseif (is_page('home')) {
    		echo "<h2>Latest Newsletter</h2>"; ?>
    		<?php query_posts('showposts=1'); ?>
    		<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><a>"<?php the_title(); ?>"</a></h2>
    			<p><?php the_time('F jS, Y') ?> </p>
    			<?php the_excerpt(); ?>
    		</div>
    		<?php endwhile; ?>
    		<?php endif; ?>
    	}
    
    	elseif
    		(is_page('membership')) {
    		echo "<h2>Membership Form</h2>";
    		echo "<a href='https://www.mywebsite.com/wpcaluwild/?page_id=16'>Please take a minute to join us by filling out our membership form.</a>"; ?>
    		}
    		</div>

    try, i just reformatted “wordpress” style. it’s easier to read and see where things are opened and closed properly

    <div id="sidebar3">
        <div id="nav">
            <ul>
                <?php wp_list_pages("title_li=&exclude=12,16,23,339"); ?>
            </ul>
        </div>
        <?php if ( is_single() ): ?>
    
        <h2>Past Newsletters</h2>
        <?php wp_get_archives('type=postbypost'); ?>
    
        <?php elseif ( is_page('home') ): ?>
        <h2>Latest Newsletter</h2>
        <?php query_posts('showposts=1'); ?>
    
        <?php if ( have_posts() ): ?>
        <?php while ( have_posts() ): the_post(); ?>
    
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            <h2><a>"<?php the_title(); ?>"</a></h2>
            <p><?php the_time('F jS, Y'); ?></p>
            <?php the_excerpt(); ?>
        </div>
    
        <?php endwhile; ?>
        <?php endif; ?>
    
        <?php elseif ( is_page('membership') ): ?>
        <h2>Membership Form</h2>
        <a href='https://www.mywebsite.com/wpcaluwild/?page_id=16'>Please take a minute to join us by filling out our membership form.</a>
        <?php endif; ?>
    </div>

    Thread Starter mjkane

    (@mjkane)

    Simplistik You Da Man! That worked. So I can learn from this, what do you mean by “wordpress” style?

    Thanks again so much!
    Michael

    I just meant the alternative syntax, it’s not “wordpress” syntax but it’s just what they use for a lot of their stuff, https://php.net/manual/en/control-structures.alternative-syntax.php

    things like

    if ():
    
    elseif ():
    
    endif;
    
    ///////////////////////
    
    while():
    
    endwhile;

    instead of

    if () {
    
    } elseif () {
    
    }
    
    ///////////////////////
    
    while() {
    
    };

    makes it easier see where blocks begin and end

    Thread Starter mjkane

    (@mjkane)

    Great, thank you. I will try coding that way.

    Now that the page is opening, the code seems to be faulty. My desire is to have in the sidebar3 of the home page (index.php) an excerpt of the current newsletter with the name as a link to its post page in its entirety. Now the link is gone and my home page maincontent is the current newsletter post, not the text that is written on the home page.

    Here’s the code, a bit altered from before reflecting my attempts to accomplish the task above.

    Thanks again for all your help.

    <div id="sidebar3">
        <div id="nav">
            <ul>
    		  <?php wp_list_pages("title_li=&exclude=12,16,21,23,339"); ?>
    		</ul>
    	</div>
    	<?php if ( is_single() ): ?>
    
    	<h2>Past Newsletters</h2>
    	<?php wp_get_archives('type=postbypost'); ?>
    
        <?php elseif ( is_page('home') ): ?>
    	<h2>Latest Newsletter</h2>
    	<?php query_posts('showposts=1'); ?>
    
    	<?php if ( have_posts() ): ?>
    		<?php while ( have_posts() ): the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><a href="<?php the_permalink() ?>"<?php the_title(); ?></a></h2>
    			<?php the_excerpt(); ?>
    		</div>
    
    		<?php endwhile; ?>
    	<?php endif; ?>
    
        <?php elseif ( is_page('membership') ): ?>
    		<h2>Membership Form</h2>
    		<a href='https://www.mywebsite.com/wpcaluwild/?page_id=16'>Please take a minute to join us by filling out our membership form.</a>
    	<?php endif; ?>
    </div>

    Uhhh LoL, I don’t quite understand what you’re asking. But are you asking for the excerpt that is in the

    is_page('home')

    condition to be the excerpt of another page? or rather the home page isn’t displaying the home page content? if it’s the later you probably need to reset the query just put

    <?php wp_reset_query(); ?>

    after the ending </div> or “the loop”

    https://codex.www.ads-software.com/Function_Reference/wp_reset_query

    Thread Starter mjkane

    (@mjkane)

    Thanks so much Simplistik, putting the reset code after “the loop” did the trick!
    Michael

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘I’m going blind tring to find the error…help please’ is closed to new replies.