使用Wordpress条件is_page

时间:2016-05-23 09:53:13

标签: wordpress conditional

我需要帮助使用Wordpress条件。下面的代码是我遇到问题的实际代码。 目标是检查页面是否为“bb_press”,如果是,则加载另一个名为“archive-forum”的模板。 如果不是,则继续使用当前模板。 我试着在开头定义if_bbpress,但我做的不对。也许结局就是问题.. 帮助赞赏

<?php
if ( is_bbpress() ) {
get_template_part('archive-forum') {
else {

<--- Continue with the current template code --->       

}
<?php endif;?>
<?php get_footer(); ?>

在此之后,我得到一个没有加载的空白页面。

编辑:这是我试图修改的原始模板。没有你的建议。尝试过他们,但我做错了什么。我在这里错过了什么?我把“if”放在错误的地方吗?到目前为止,谢谢大家的帮助。

<?php
/**
* Directory archive page
*
**/
get_header(); //Header Portion
$tmpdata = get_option('templatic_settings');
global $posts,$htmlvar_name;

do_action('after_event_header');

/* Left content side bar for all pages */
global $htmlvar_name;
if(function_exists('tmpl_get_category_list_customfields')){
$htmlvar_name = tmpl_get_category_list_customfields(CUSTOM_POST_TYPE_EVENT);
}else{
global $htmlvar_name;
}
if (!is_active_sidebar( 'tmpl_listings_left_content') ){
$class="content-middle";
}else{
$class="";
}

/* Here we use for Show left content sidebar , it can be use for many other purpose too */
do_action('tmpl_all_pages_left_content');   
?>
<div class="content-sidebar <?php echo $class; ?>">

<script type="text/javascript">
var category_map = '<?php echo $tmpdata['category_map'];?>';
<?php if($_COOKIE['display_view']=='event_map' && $tmpdata['category_map']=='yes'):?>
jQuery(function() {         
jQuery('#listpagi').hide();
});
<?php endif;?>
</script>
<!--taxonomy  sidebar -->

<!--end taxonomy sidebar -->
<div class="page-head">
<?php 
/* back page link */
tmpl_back_link();
do_action('after_directory_header'); /*do action for display the breadcrumb in between header and container. */
do_action('directory_before_container_breadcrumb');
?>
</div>
<?php 
if ( is_active_sidebar('listingcategory_listing_above_content') ) : ?>
<div class="filters">
<div id="sidebar-primary" class="sidebar">
<?php dynamic_sidebar('listingcategory_listing_above_content'); ?>
</div>
</div>
<?php  endif; ?>
<div class="view_type_wrap">
<?php /*do action to display the breadcrumb  inside the container. */

/* Archive page title */
do_action('directory_before_archive_title'); ?>              
<h1 class="loop-title">
<?php echo ucfirst(apply_filters('tevolution_archive_page_title','Listing'));?>     
</h1>
<?php
if($archive_description[CUSTOM_POST_TYPE_LISTING]['description'] !=''){
?>
<div class="archive-meta"><?php echo $archive_description[CUSTOM_POST_TYPE_LISTING]['description']; ?></div>
<?php 
}
do_action('directory_after_archive_title');  
do_action('directory_before_loop_archive');
?>

</div>

<div id="content" class="contentarea large-9 small-12 columns <?php directory_class();?>">

<!--Start loop archive page-->  
<div id="loop_listing_taxonomy" class="search_result_listing <?php if($tmpdata['default_page_view']=="gridview"){echo 'grid';}else{echo 'list';}?>" <?php if( is_plugin_active('Tevolution-Directory/directory.php') && $tmpdata['default_page_view']=="mapview"){ echo 'style="display: none;"';}?>>
<?php if (have_posts()) : 
while (have_posts()) : the_post();
do_action('directory_before_post_loop');?>

<div class="post <?php templ_post_class();?>" >  
<?php 
/* Hook to display before image */  
do_action('tmpl_before_category_page_image');

/* Hook to Display Listing Image  */
do_action('directory_category_page_image');

/* Hook to Display After Image  */                       
do_action('tmpl_after_category_page_image'); 

/* Before Entry Div  */ 
do_action('directory_before_post_entry');?> 

<!-- Entry Start -->
<div class="entry"> 

<?php  /* do action for before the post title.*/ 
do_action('directory_before_post_title');         ?>
<div class="listing-wrapper">
<!-- Entry title start -->
<div class="entry-title">

<?php do_action('templ_post_title');                /* do action for display the single post title */?>

</div>

<?php do_action('directory_after_post_title');          /* do action for after the post title.*/?>

<!-- Entry title end -->

<!-- Entry details start -->
<div class="entry-details">

<?php  /* Hook to get Entry details - Like address,phone number or any static field  */  
do_action('listing_post_info');   ?>     

</div>
<!-- Entry details end -->
</div>
<!--Start Post Content -->
<?php /* Hook for before post content . */ 

do_action('directory_before_post_content'); 

/* Hook to display post content . */ 
do_action('templ_taxonomy_content');

/* Hook for after the post content. */
do_action('directory_after_post_content'); 
?>
<!-- End Post Content -->
<?php 
/* Hook for before listing categories     */
do_action('directory_before_taxonomies');

/* Display listing categories     */
do_action('templ_the_taxonomies'); 

/* Hook to display the listing comments, add to favorite and pinpoint   */                      
do_action('directory_after_taxonomies');?>
</div>
<!-- Entry End -->
<?php do_action('directory_after_post_entry');?>
</div>
<?php do_action('directory_after_post_loop');
endwhile; 
wp_reset_query();
else:?>
<p class='nodata_msg'><?php _e( 'Apologies, but no results were found for the requested archive.', 'templatic' ); ?></p>              
<?php endif;
if($wp_query->max_num_pages !=1):?>
<div id="listpagi">
<div class="pagination pagination-position">
<?php if(function_exists('pagenavi_plugin')) { pagenavi_plugin(); } ?>
</div>
</div>
<?php endif;?>
</div>


<!--End loop archive page -->
</div>

</div>
<?php get_footer(); ?>

2 个答案:

答案 0 :(得分:2)

这是您的病情的正确代码,并将正常工作。您必须关闭该条件的支具。检查条件参考click here

    NoteList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ID = view.getText().toString();
        }
    });

答案 1 :(得分:1)

如果您使用括号,则无需使用endif;每一行endif;<?php以及每行结束?>都非常难看。 <!--在PHP代码中无效。您需要在;

之后添加get_template_part('archive-forum');
<?php
    if ( is_bbpress() ) {
       get_template_part('archive-forum'); 
    } else {
       //Continue with the current template code

    }
    get_footer(); 
?>
 <!-- More none php code here. If there are no more php code, you can leave ?> -->