2016-05-23 31 views
-1

私はWordpressの条件付きで助けが必要です。以下のコードは私が問題を抱えている実際のコードです。 目的はページが「bb_press」であるかどうかを確認し、そうであれば「archive-forum」という別のテンプレートを読み込みます。 そうでない場合は、現在のテンプレートを使用し続けます。 最初にis_bbpressを定義しようとしましたが、何か正しいことをしていません。おそらく、エンディングが問題..です ヘルプは、この後Wordpressの条件付きis_pageを使用

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

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

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

に感謝私がロードされた何もない空白のページを取得しています。

EDIT:これは私が修正しようとしているオリジナルのテンプレートです。あなたの提案なし。彼らを試してみましたが、私は間違ったことをしています。私はここで何が欠けていますか?私は間違った場所に "もし"を置いていますか?これまでのご協力ありがとうございました。

<?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

;を追加する必要があり、正常に動作します。あなたは条件のブレースを閉じる必要があります。状態参照のためにこれを確認してください

<?php 
      if (is_bbpress()) { 
       get_template_part('archive-forum'); 
      } else { 
       // continue with the current template code 
      } 
      get_footer(); 
     ?> 
1

あなたは括弧を使用している場合は、この全体のendif;と開口部<?phpendif;を使用する必要があり、すべての行で?>を閉じることは非常に醜いですしないでください。 <!--は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 ?> --> 
+0

私は本当にPHPに苦しんでいます。 {と}の間に完全なテンプレートのコードを挿入すると、空白のページが再び表示されます。しかし、「hello world」というエコーだけを出力すると、正しく表示されます。だから私はテンプレートコードを貼り付けることができないと思いますか? –

+0

ページに構文エラーがある可能性があります。あなたのファイルの最上部に 'error_reporting(E_ALL);と' ini_set( 'display_errors'、1); ' – vaso123

関連する問題