Support » Fixing WordPress » if else statement

  • Resolved vince23

    (@vince23)


    Hey,

    I’d like to inculde this little peace of code on my start page (I’m using Woocommerce) and therefore I need a “if else statement” which checks if its the front page.

    <?php
    		$id = 43;
    		$p5 = get_page($id);?>
    		<article>
    
    <div class="entry-content">
    <?php  echo apply_filters('the_content', $p5->post_content); ?>
    				<?php wp_link_pages() ?>
    		</article>
    		</div>	
    
    		<?php
    		$id = 26;
    		$p6 = get_page($id);?>
    		<div class="about">
    		<article class="typ">
    		<header class="entry-header">
    				<h1 class="entry-title"> <?php  echo apply_filters('the_title', $p6->post_title); ?> </h1>
    		</header>
    				<div id="pad" class="entry-content" >
    				<?php  echo apply_filters('the_content', $p6->post_content); ?>
    				<?php wp_link_pages() ?>
    		</div>
    		</article>
    		</div>

    I think it going to be this

    <?php
    if ( is_home() ) {
    
    } else {
    
    }
    ?>

    but I m not sure how to use it.

    Maybe u could help me out,

    thanks,

    vince

Viewing 8 replies - 1 through 8 (of 8 total)
  • webdesignerchristian

    (@webdesignerchristian)

    <?php
    if ( is_home() ) {
    
    	$id = 43;
    		$p5 = get_page($id);?>
    		<article>
    
    <div class="entry-content">
    <?php  echo apply_filters('the_content', $p5->post_content); ?>
    				<?php wp_link_pages() ?>
    		</article>
    		</div>	
    
    		<?php
    		$id = 26;
    		$p6 = get_page($id);?>
    		<div class="about">
    		<article class="typ">
    		<header class="entry-header">
    				<h1 class="entry-title"> <?php  echo apply_filters('the_title', $p6->post_title); ?> </h1>
    		</header>
    				<div id="pad" class="entry-content" >
    				<?php  echo apply_filters('the_content', $p6->post_content); ?>
    				<?php wp_link_pages() ?>
    		</div>
    		</article>
    		</div>
    
    }?>
    catacaustic

    (@catacaustic)

    very awesome

    Also note that it can depend on how your site is set up, but you may also need the is_front_page() function as well, so it would be something lik ethis:

    <?php
        if ( is_home() || is_front_page() ) {
            **  Your code in here  **
        }
    ?>

    @catacaustic

    hmm ,thank you but this gives me an error on the line where my code starts (the last <?php in this case).:

    <?php
        if ( is_home() || is_front_page() ) {
           <?php

    Is it possible to put “<?php” inside another “<?php” at all or do I have to use a special statement ?

    webdesignerchristian

    (@webdesignerchristian)

    sorry was sloppy mised end code. but validates now

    <?php
       if ( is_home() || is_front_page() ){
    
    	$id = 43;
    		$p5 = get_page($id);?>
    		<article>
    
    <div class="entry-content">
    <?php  echo apply_filters('the_content', $p5->post_content); ?>
    				<?php wp_link_pages() ?>
    		</article>
    		</div>	
    
    		<?php
    		$id = 26;
    		$p6 = get_page($id);?>
    		<div class="about">
    		<article class="typ">
    		<header class="entry-header">
    				<h1 class="entry-title"> <?php  echo apply_filters('the_title', $p6->post_title); ?> </h1>
    		</header>
    				<div id="pad" class="entry-content" >
    				<?php  echo apply_filters('the_content', $p6->post_content); ?>
    				<?php wp_link_pages() ?>
    		</div>
    		</article>
    		</div>
    
    <?php }?>

    @webdesignerchristian:

    in your case it gives me an error “Parse error: syntax error, unexpected end of file” and a line number at the end of the document.

    here is a cleaner version of the code, maybe u can spot the error:

    <?php
    if ( is_home() || is_front_page() ) {
    
    		$id = 43;
    		$p5 = get_page($id);?>
    
    		<article>
    		<div class="entry-content">
    		<?php  echo apply_filters('the_content', $p5->post_content); ?>
    		<?php wp_link_pages() ?>
    		</div>
                    </article>
    
    		<?php
    		$id = 26;
    		$p6 = get_page($id);?>
    
                    <article>
    		<div class="entry-content">
    		<?php  echo apply_filters('the_content', $p6->post_content); ?>
    		<?php wp_link_pages() ?>
    		</div>
                    </article>
    
    }?>
    Moderator stephencottontail

    (@stephencottontail)

    Did you see the corrected version that webdesignerchristian posted? (It looks like he posted around the same time you did.) It fixes the “unexpected end of file” error.

    This works ! Thank you guys a lot !!

    webdesignerchristian

    (@webdesignerchristian)

    welcome vince, please mark thread resolved

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘if else statement’ is closed to new replies.