Forums

[resolved] Category Exclusion... small Index.php Coding Problem - (18 posts)

  1. douglasbell01
    Member
    Posted 1 year ago #

    Hello,

    I've been trying to code a query post into the site's index.php so that the 'news' category shows up in the 'news feed' - with all other categories excluded. The category ID=1 for 'news'.

    This idea worked perfectly for me on another theme, but this time it throws up an 'syntax error on line 25' of Index.php - I could do with some expert advice on solving this. Maybe I need to sort out the line spacing, maybe a stray/missing bracket? Any tips on fixing this code would mean a lot.

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. David Gwyer
    Member
    Posted 1 year ago #

    Can you use the pastebin so I can view your code.

  3. douglasbell01
    Member
    Posted 1 year ago #

  4. David Gwyer
    Member
    Posted 1 year ago #

    Are you missing a semi-colon on line 19?

  5. douglasbell01
    Member
    Posted 1 year ago #

    I haven't made a change to 19, as far as I'm aware. I'm happy to try inserting a semi-colon, but I'm not sure where to place it...

    Any other suggestions?

  6. David Gwyer
    Member
    Posted 1 year ago #

    Try changing line 19 from:

    <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title() ?></a></h2>

    to:

    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title() ?></a></h2>

    Also what does the syntax error say?

  7. douglasbell01
    Member
    Posted 1 year ago #

    Hi , and thanks for your help. The semi colon is now in place, but there has been no change to the original problem unfortunately.

    Parse error: syntax error, unexpected T_ELSE in /home/content/d/o/u/douglasbell/html/Chariots/wp-content/themes/gridfocus/index.php on line 25

  8. David Gwyer
    Member
    Posted 1 year ago #

    Also add a semi-colon after 'the_title()' on line 25 just for completion.

    I see your problem now, your code is structured in the following way:

    if
      while
      endwhile
    else
    endif

    Your problem is because there is no opening if. This might have been missed off when copying/pasting code?

  9. douglasbell01
    Member
    Posted 1 year ago #

    Hi,

    do you mean another semi-colon on line 19? (as below)

    <h2>" title="<?php the_title(); ?>"><?php the_title(); ?></h2>

    I'm not sure how an opening 'if' has gone missing - having been very careful with pasting, and unfortunately I'm not sure how to replace it exactly...

    Many thanks again for your help...!

  10. douglasbell01
    Member
    Posted 1 year ago #

    I've spotted where the missing IF was... here is the original code from the top of the Index.php - I'm stuck on how to fix this still, so any help would be hugely appreciated. Learning by doing.

    <div id="filler" class="fix">
    	<div id="mainColumn">
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div id="post-<?php the_ID(); ?>" class="post">
    				<div class="postMeta">
    				<p class="container">
    
    				</p>
    			</div>

    [Please post code snippets between backticks or use the code button.]

  11. David Gwyer
    Member
    Posted 1 year ago #

    Try adding:

    <?php if (have_posts()) : ?>

    directly under the line:

    <?php query_posts('category=1'); ?>

  12. douglasbell01
    Member
    Posted 1 year ago #

    Thanks David.

    It seems to have resulted in a new error:

    Parse error: syntax error, unexpected $end in /home/content/d/o/u/douglasbell/html/Chariots/wp-content/themes/gridfocus/index.php on line 46

    Any thoughts?

  13. David Gwyer
    Member
    Posted 1 year ago #

    Could you put the whole files updated code on pastebin?

  14. douglasbell01
    Member
    Posted 1 year ago #

    Inndex.php as it is now http://pastebin.com/SeLWVrpU, resulting in:

    Parse error: syntax error, unexpected $end in /home/content/d/o/u/douglasbell/html/Chariots/wp-content/themes/gridfocus/index.php on line 46

  15. douglasbell01
    Member
    Posted 1 year ago #

  16. David Gwyer
    Member
    Posted 1 year ago #

    There is now no matching `endif;' directly before the line:

    <div id="paginateIndex" class="fix">

    This was present before.

  17. douglasbell01
    Member
    Posted 1 year ago #

    David, you're a legend! I was playing with the endif, when my concentration was broken by a phone call, so must have cut it and not put it back!

    Index.php now working perfectly (having changed the quesry slightly to:

    <?php query_posts('category_name=news'); ?>

    Link to modified Gridfocus Index.php file for other users: http://pastebin.com/LEUcwwC7

  18. David Gwyer
    Member
    Posted 1 year ago #

    Glad you got it sorted. :)

    Can you mark the thread as resolved. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic