<div id="primary">
<div id="content" role="main">
<?php
$terms = get_terms("tagportfolio");
$count = count($terms);
echo '<ul id="portfolio-filter">';
echo '<li><a href="#all" title="">All</a></li>';
if ( $count > 0 ){
foreach ( $terms as $term ) {
$termname = strtolower($term->name);
$termname = str_replace(' ', '-', $termname);
echo '<li><a href="#'.$termname.'" title="" rel="'.$termname.'">'.$term->name.'</a></li>';
}
}
echo "</ul>";
?>
<?php
$loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1));
$count =0;
?>
<div id="portfolio-wrapper">
<ul id="portfolio-list">
<?php if ( $loop ) :
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$post = '';
$terms = get_the_terms($post->ID, 'tagportfolio' );
if ( $terms && ! is_wp_error( $terms ) ) :
$links = array();
foreach ( $terms as $term )
{
$links[] = $term->name;
}
$links = str_replace(' ', '-', $links);
$tax = join( " ", $links );
else :
$tax = '';
endif;
?>
<?php $infos = get_post_custom_values('_url'); ?>
<li class="portfolio-item <?php echo strtolower($tax); ?> all">
<div class="thumb"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail('project-large'); ?></a></div>
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<p class="excerpt"><a href="<?php the_permalink() ?>"><?php echo get_the_excerpt(); ?></a></p>
<p class="links"><a href="<?php echo $infos[0]; ?>" target="_blank">Live Preview →</a> <a href="<?php the_permalink() ?>">More Details →</a></p>
</li>
<?php endwhile; else: ?>
<li class="error-not-found">Sorry, no portfolio entries for while.</li>
<?php endif; ?>
</ul>
<div class="clearboth"></div>
</div> <!-- end #portfolio-wrapper-->
</div><!-- #content -->
</div><!-- #primary -->
当上面的wordpress代码调试成立时,我收到此通知: 注意:未定义的变量:在第50行的C:.... php中发布 注意:尝试在第50行的C:.... php中获取非对象的属性
第50行是:$ terms = get_the_terms($ post-&gt; ID,'tagportfolio');
请帮我解决这个问题并解除通知?
答案 0 :(得分:1)
删除该行$post = '';
$post
是global
变量。
然后您尝试访问$post
属性
$terms = get_the_terms($post->ID, 'tagportfolio' );
这就是为什么你得到未定义的变量:在C:中发布
答案 1 :(得分:0)
您可以尝试以下方式,
就是这样:
global $wp_query;
$post = $wp_query->post;