0

I would like to have two different search results depending on the page, that the user is on.

I have duplicated how the previous search contents would display, added the extra code that I want the staff search to show, and then put an if statement around it.

If user is on page 'staff' - then show this Else show this.

I cant seem to get the if-statement to work, any help would be appreciated.

EDIT

This is the original working code, before i put the IF statement in, to try and create another set of results for staff searching from a specific page.

<?php
if ( is_home() ) {
    $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );

    $args = array(
        'showposts' => (int) get_option('trim_homepage_posts'),
        'paged' => $paged,
        'category__not_in' => (array) get_option('trim_exlcats_recent'),
    );
    query_posts( apply_filters( 'et_home_args', $args ) );
}
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="entry post clearfix preownedSearch">

    <h2 class="et_pt_portfolio_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php 
        $index_postinfo = get_option('trim_postinfo1');
        if ( $index_postinfo ){
            echo '<p class="meta">';
            et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
            echo '</p>';
        }
    ?>

    <div class="post-content clearfix">
        <?php
            $thumb = '';
            $width = apply_filters('et_image_width',260);
            $height = apply_filters('et_image_height',170);
            $classtext = '';
            $titletext = get_the_title();
            $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
            $thumb = $thumbnail["thumb"];
        ?>
        <?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
            <div class="featured_box filter">
            <a href="<?php the_permalink(); ?>">
            <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>  
                </a>    
            </div>  <!-- end .featured_box -->
        <?php } ?>
    </div>
</article>  <!-- end .post-->

<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>

This is the coding after i've put the if-statement in -

<?php
if ( is_home() ) {
    $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );

    $args = array(
        'showposts' => (int) get_option('trim_homepage_posts'),
        'paged' => $paged,
        'category__not_in' => (array) get_option('trim_exlcats_recent'),
    );
    query_posts( apply_filters( 'et_home_args', $args ) );
}
?>

<?php if (is_page('stock-managers')) { ?>

<article class="entry post clearfix preownedSearch">

    <h2 class="et_pt_portfolio_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php the_meta(); ?></a></h2>
    <?php 
        $index_postinfo = get_option('trim_postinfo1');
        if ( $index_postinfo ){
            echo '<p class="meta">';
            et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
            echo '</p>';
        }
    ?>

    <div class="post-content clearfix">
        <?php
            $thumb = '';
            $width = apply_filters('et_image_width',260);
            $height = apply_filters('et_image_height',170);
            $classtext = '';
            $titletext = get_the_title();
            $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
            $thumb = $thumbnail["thumb"];
        ?>
        <?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
            <div class="featured_box filter">
            <a href="<?php the_permalink(); ?>">
            <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>  
                </a>    
            </div>  <!-- end .featured_box -->
        <?php } ?>
    </div>
</article>  <!-- end .post-->

<?php } else { ?>   

<article class="entry post clearfix preownedSearch">

    <h2 class="et_pt_portfolio_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php 
        $index_postinfo = get_option('trim_postinfo1');
        if ( $index_postinfo ){
            echo '<p class="meta">';
            et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
            echo '</p>';
        }
    ?>

<div class="post-content clearfix">
        <?php
            $thumb = '';
            $width = apply_filters('et_image_width',260);
            $height = apply_filters('et_image_height',170);
            $classtext = '';
            $titletext = get_the_title();
            $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
            $thumb = $thumbnail["thumb"];
        ?>
        <?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
            <div class="featured_box filter">
            <a href="<?php the_permalink(); ?>">
            <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>  
                </a>    
            </div>  <!-- end .featured_box -->
        <?php } ?>
    </div>
</article>  <!-- end .post-->

<?php } endif; ?>




<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>

Edit 2 Match

<?php
if ( is_home() ) {
    $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );

    $args = array(
        'showposts' => (int) get_option('trim_homepage_posts'),
        'paged' => $paged,
        'category__not_in' => (array) get_option('trim_exlcats_recent'),
    );
    query_posts( apply_filters( 'et_home_args', $args ) );
}
?>

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

<?php if ($post->post_name('stock-managers')) { ?>

<article class="entry post clearfix preownedSearch">

    <h2 class="et_pt_portfolio_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php the_meta(); ?></a></h2>
    <?php 
        $index_postinfo = get_option('trim_postinfo1');
        if ( $index_postinfo ){
            echo '<p class="meta">';
            et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
            echo '</p>';
        }
    ?>

    <div class="post-content clearfix">
        <?php
            $thumb = '';
            $width = apply_filters('et_image_width',260);
            $height = apply_filters('et_image_height',170);
            $classtext = '';
            $titletext = get_the_title();
            $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
            $thumb = $thumbnail["thumb"];
        ?>
        <?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
            <div class="featured_box filter">
            <a href="<?php the_permalink(); ?>">
            <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>  
                </a>    
            </div>  <!-- end .featured_box -->
        <?php } ?>
    </div>
 </article>     <!-- end .post-->

 <?php else : ?>    

 <article class="entry post clearfix preownedSearch">

    <h2 class="et_pt_portfolio_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php 
        $index_postinfo = get_option('trim_postinfo1');
        if ( $index_postinfo ){
            echo '<p class="meta">';
            et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
            echo '</p>';
        }
    ?>

    <div class="post-content clearfix">
        <?php
            $thumb = '';
            $width = apply_filters('et_image_width',260);
            $height = apply_filters('et_image_height',170);
            $classtext = '';
            $titletext = get_the_title();
            $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
            $thumb = $thumbnail["thumb"];
        ?>
        <?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
            <div class="featured_box filter">
            <a href="<?php the_permalink(); ?>">
            <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>  
                </a>    
            </div>  <!-- end .featured_box -->
        <?php } ?>
    </div>
</article>  <!-- end .post-->

<?php endif; ?>

<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>
user2271599
  • 23
  • 1
  • 1
  • 4

1 Answers1

1

Your php Syntax is wrong.

PHP Syntax Check: Parse error: syntax error, unexpected 'endif' (T_ENDIF) in your code on line 7 <?php } endif;?> PHP Syntax Check: Errors parsing your code

With removing endif;you're good to go

<?php if (is_page('staff')) { ?>

<article class="entry post clearfix">
    <-- Title / Thumbnail / Price / Description coding -->
</article> 

 <?php } else { ?>  

<article class="entry post clearfix">
    <-- Title / Thumbnail / Description coding -->
</article> 

<?php }  ?>

Learn more about PHP's Alternativ syntax

See explanation of using if(condition){}and if(condition):endif; at this answer

Edit:

If you're using is_page within the Loop, it'll be allways false /see Source.

Instead you could compare a chosen value (here it's staff) to any other field of your current post/page.

<?php if ( $post->post_name=='staff' ) { ?>

<article class="entry post clearfix">
    <-- Title / Thumbnail / Price / Description coding -->
</article> 

 <?php } else { ?>  

<article class="entry post clearfix">
    <-- Title / Thumbnail / Description coding -->
</article> 

<?php }  ?>

Edit No.2:

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

    <?php if ($post->post_name('stock-managers')) { ?>

        <article class="entry post clearfix preownedSearch">

        </article>  <!-- end .post-->

    <?php else : ?>   

        <article class="entry post clearfix preownedSearch">


        </article>  <!-- end .post-->

    <?php endif; ?>

<?php
endwhile;
?>
Community
  • 1
  • 1
Robin Vinzenz
  • 1,247
  • 15
  • 19
  • Thanks for the response, I tried that and unfortunately it didn't work either. There must be something going on around it, thats not allowing it to work. – user2271599 Apr 29 '15 at 16:09
  • This tag (is_page) must be used BEFORE The Loop and does not work inside The Loop (see Notes below). https://codex.wordpress.org/Function_Reference/is_page – Robin Vinzenz Apr 29 '15 at 16:13
  • Ive added in more code, to give a better idea of what i'm working around. When I remove the last section of coding, with the endwhile, Only 1 result will appear, without the extra info asked for. – user2271599 Apr 29 '15 at 16:35
  • You're just replacing the Loop If with your own if thats not correct. You should enable Debug Mode of Wordpress to see PHP Syntax Errors... Check again my edited post that should work for you now. Otherwise i can't help you out.... – Robin Vinzenz Apr 29 '15 at 17:12
  • I added the code, that i posted above (edit two match), it didnt change anything, then I used debug and only this appeared: "wp_enqueue_script was called incorrectly" – user2271599 Apr 30 '15 at 11:52
  • Thanks, for all the help, its appreciated. I really don't know its not working, like it should. – user2271599 Apr 30 '15 at 12:05
  • Hey Robin, my skype is alex.milne.1989 – user2271599 Apr 30 '15 at 13:14