Hello @aikibe I hope you are well today
Actually I can see another problem related to the plugin quadmenu, can you try desactivate this one.
Thread Starter
aikibe
(@aikibe)
Hello Andres, I thank you. This cleared the quad problems but still the page error comes up. There is no clarity why it is doing this, the code seems correct.
If you know php, does it make sense to put a if and else statement with ending a endif? you would expect it to endif after the if.
also after the <?php else : ?> is it normal to place a function with < ?php infront of it and not without?
I am not familiar with php so please explain m8.
You have nested <?php ?> blocks like we nest HTML elements. That’s a no-no in PHP. Terminate one before starting another. There may also be imbalanced <?php ?> blocks — opened with <?php with no closing ?>, or vice versa. If there is not intervening HTML content between PHP blocks, there’s no need to repeatedly close and open them. People do it, it’s valid to do so, but I think doing so is silly.
You also have missing line terminators. Essentially, all lines should end with ; or :. Only use : if there is some subsequent end{$something}; that relates to it. This is OK:
if ( true ) :
// do something
else :
// do something else
endif;
The endif; is terminating the entire if/elseif/else structure. Maybe it’s not totally logical, but it’s valid syntax for PHP none the less. If it bugs you, you could use curly brace delimiters instead:
if ( true ) {
// do something
} else {
// do something else
}
My line terminating rule above isn’t precisely correct, there are exceptions (like my last example) and variations that would still be valid, and strict adherence could in some cases be invalid. But following it here should help you get to error free code.
Thread Starter
aikibe
(@aikibe)
Dont nest <?php ?> blocks, and do not open one before terminating other so no <?php
<?php ?> ?> Dont reopen them just use the one you started with gotcha!
You can use this as much as you like, but it has to end with ?> not nested.
Than do I see <?php ?> blocks like a initialization or a translation? because they are only for initialization as php language?
Is this ok?
<?php if ( something ); ?>
<?php else : (something second); ?> Per if statement.
<div> </div> I can leave out of the php blocks?
The page is now coming out without template.
Ok like c++ ” ; ” ends a line.
and use ” : ” for a follow up,
ah } is like endif; that is better yes
I get what you mean, sometimes without the : it still is ok, like a single if statement.
I can try it like this:
<?php
/**
* The template for displaying all pages
*
* This is the template that displays all pages by default.
*
* @link https://codex.ww.wp.xz.cn/Template_Hierarchy
*/
?>
get_header();
<div id="primary" class="content-area">
<main id="main" class="site-main post-wrap" role="main">
<?php // If comments are open or we have at least one comment, load up the comment template. ?>
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
get_template_part( 'content', 'page' );
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile;
?>
<?php
else :
get_template_part( 'content', 'none' );
?>
<?php
endif;
?>
<?php consultent_edit_link(); ?>
<?php get_footer(); ?>
</main> <!-- /main -->
</div>
<!-- /.post-wrap -->
If it’s code it belongs in a <?php ?> block. If it’s HTML, it belongs outside of any PHP block.
Move get_header(); into a PHP block or create one just for that one line. Other than that, the template code all looks like proper PHP syntax. Well done!
However
Is this ok?
<?php if ( something ); ?>
<?php else : (something second); ?>
No, because you terminated the if() line with ;, so that’s the end of it, the subsequent else : no longer relates back to the if(). Either terminate with a : (think of it like a continuation character) or delimit with curly braces. If you use :, you need an endif;. But not with curly braces.
<?php if ( true||false ) :
some_function(); ?>
<?php else :
some_other_function();
endif; ?>
Or
<?php if ( true||false ) {
some_function(); ?>
<?php } else {
some_other_function();
} ?>
The function call the if(): or else: pertains to can be on the same line, but your code will be easier to read if they occur on their own line and are indented. It’s a matter of style more than right or wrong. There are several accepted styles. Compliance is optional. What you should at least do is use a style that maximizes readability and use it consistently. IMO readability and consistency is more important than following any particular established style.