【发布时间】:2017-03-14 02:18:55
【问题描述】:
我编写了一个简码,用于在分配给特定团队成员的同一类别的帖子中显示自定义帖子类型(包含团队成员个人资料)的帖子。短代码完美运行,但我在内容下方的页面模板中的 php 函数(特别是第一个 if 语句)不再起作用。奇怪的是,如果我删除第一个 if 语句,内容下方的 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: <?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; ?>
任何帮助将不胜感激
【问题讨论】: