两个Wordpress搜索结果页面

时间:2015-04-29 15:50:11

标签: wordpress search if-statement

我希望根据用户所在的页面有两种不同的搜索结果。

我重复了之前搜索内容的显示方式,添加了我希望员工搜索显示的额外代码,然后在其周围添加if语句。

如果用户在页面'员工' - 然后显示这个 其他 显示这个。

我似乎无法使用if语句,任何帮助都会受到赞赏。

修改

在我输入IF语句之前,这是原始的工作代码,试图为从特定页面搜索的员工创建另一组结果。

<?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(); ?>

这是我将if语句放入 -

之后的编码
<?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(); ?>

编辑2匹配

<?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(); ?>

0 个答案:

没有答案