2017-03-14 8 views
0

私は、特定のチームメンバーに割り当てられた同じカテゴリの投稿にカスタム投稿タイプの投稿(チームメンバープロフィールを含む)を表示するショートコードを書いています。ショートコードは完全に機能しますが、コンテンツの下のページテンプレートにあるphp関数(特に最初のif文)は機能しなくなりました。私は文の場合は、最初に削除する場合不思議なコンテンツを表示し、以下のPHPが正しくWordpressのショートコードが機能しない以下のPHPが発生する

私のショートコードは次のとおりです。

function team_embed() { 
ob_start(); 
global $post; 
// get the domain page category 
$pagecat = get_the_category(); 
$CategoryName = $pagecat[0]->cat_name; 
$slug = $pagecat[0]->slug; 
$slug1 = $pagecat[0]->slug; 
$exp = '_experience'; 
$experience = $slug1 .= $exp; 
$query = array('post_type' => 'team', 'posts_per_page' => -1, 'category_name' => $slug); 
$loop = new WP_Query($query); 
while ($loop->have_posts()) : $loop->the_post(); 
    $phone = get_post_meta($post->ID, 'Phone Number', true); 
    $linkedin = get_post_meta($post->ID, 'Linkedin', true); 
    ?> 
    <div class="team-embed-wrapper"> 
     <div class="team-embed"> 
      <h3><?php the_title(); ?></h3> 
       <div class="team-embed-thumbnail"> 
        <?php the_post_thumbnail(); ?> 
       </div> 
      <div class="team-embed-excerpt"> 
       <?php 
        if ($phone) { ?> 
         Phone:&nbsp;<?php echo $phone; ?><br /> <?php } 
        else {}  
        if ($linkedin) { 
         echo $linkedin; ?><br /> <?php } 
        else {} ?> 
       <br /> 
       <a href="<?php the_permalink() ?>" class="rm-button">Read Complete Profile</a> 
      </div> 
     </div> 
     <div class="team-embed-experience"> 
      <strong><?php echo $CategoryName; ?> domain related experience:</strong><br /> 
      <p><?php echo get_field($experience); ?></p> 
     </div> 
    </div> 
    <div style="clear:both"></div> 
<?php  
endwhile; 
$output = ob_get_clean();  
return $output; 
} 
add_shortcode('Team_Embed', 'team_embed'); 

ショートをされて使用していないときに動作し、私のページテンプレート(中ページの内容以下のコード:

<!-- Add closures and Case Studies if available --> 
<?php 
    // get the category 
    $category = get_the_category(); 
    $firstCategory = $category[0]->cat_name; 
?> 
<?php if(get_field('tclosure_add') == 'yes'): ?> 
    <h2><?php echo $firstCategory; ?> closures</h2> 
    <div class="closure-cat"> 
    <?php echo do_shortcode("[pt_view id=1723554lt4 cat='$firstCategory' limit=3]"); ?> 
    <a class="rm-button" href="/experience">View All Company Closures</a></div> 
<?php endif; ?> 
<?php if(get_field('case_studies_add') == 'yes'): ?> 
    <h2><?php echo $firstCategory; ?> Case Studies</h2> 
    <div class="case-study-embed-wrapper"> 
     <?php echo do_shortcode("[pt_view id=2c2b5b7ulr cat='$firstCategory' limit=3]"); ?> 
    </div> 
    <a class="rm-button" href="/representative-engagements/#case-studies">View All Company Case Studies</a> 
    <?php endif; ?> 

どれヘルプが

答えて

0

をいただければ幸い私はあなたがページテンプレートコードをいじっているあなたのメインクエリをいじりすることができると思います。

あなたが投稿

<?php foreach($loop->posts as $post): ?> 
    <!-- Gather info here, remember that the $post is not global so you will have to use functions that can accept a post ID... --> 
<?php endforeach; 

上のforeachを使用するか、またはあなたは、ループの最後で wp_reset_query()を使用することができます。

動作しない場合は教えてください。

+0

ありがとうございました! 私はそれがそれのような単純なものであることを知っていました。私はwp_reset_query()を試みました。私は$出力の後にそれを置いた。ライン。 最後に置いてください。あなたが完全に働いたことを示したように。 もう一度おねがいしますが、私は数日間これと戦ってきました。 – emat

+0

ようこそ@emat –

関連する問題