【发布时间】:2015-07-02 15:48:26
【问题描述】:
我有这段代码可以在块中显示新闻。但是当将此代码包含在function.php 中时,以短代码调用它。它显示白页,没有显示任何错误。
Sow 哪里出错了??
由于某种原因,当我编辑我的functions.php 时,各种页面变白。例如,使用以下代码:
function box_news_eight( $atts ) {
$code = '<div class="cf"></div>
<div class="box-home box-news-seven nb-eight">
<div class="box-inner">
<div class="box-wrap">';
$query = new WP_Query( array( 'posts_per_page' => 1, 'cat' => 4, 'ignore_sticky_posts' => 1, 'no_found_rows' => true, 'cache_results' => false ) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
if ( $i_cont == 0 ) { $post_class = ' ws-post-first'; } else { $post_class = ' ws-post-sec'; }
if ( has_post_thumbnail() ) { $has_class = ''; } else { $has_class = ' no-thumb'; }
$code .= ' <div class="post'.$post_class.','. $has_class.'" role="article" itemscope="" itemtype="http://schema.org/Article">';
$post_sidebars = '';
if ( $post_sidebars == 'sideNo' ) {
if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) :
$code .= ' <div class="ws-thumbnail"><a href="'.get_the_permalink().'" rel="bookmark">
.'get_the_post_thumbnail( 'bd-normal' ).'
</a></div>';
endif;
} else {
if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) :
$code .= '<div class="ws-thumbnail"><a href="'.get_the_permalink().'" rel="bookmark">';
get_the_post_thumbnail( 'bd-large' );
$code .= '</a></div>';
endif;
}
$code .= '<div class="ws-cap">
<div class="post-cats-bd">';
get_the_category( ' ' );
$code .= '</div>
<div class="ws-cap-inner">
<h3 itemprop="name" class="entry-title"><a itemprop="url" href="'.get_permalink( $post->ID ).'" rel="bookmark">'.get_the_title()'.</a></h3>
<div class="post-date-bd">'.
get_time().'
</div>
</div>
</div>
</div>';
$i_cont++; endwhile; endif; wp_reset_postdata(); wp_reset_query();
$query = new WP_Query( array( 'ignore_sticky_posts' => 1, 'offset'=>1, 'posts_per_page' => 4, 'cat' => 4, 'no_found_rows' => true, 'cache_results' => false ) );
update_post_thumbnail_cache( $query );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
if ( $i_cont == 0 ) { $post_class = ' ws-post-first'; } else { $post_class = ' ws-post-sec'; }
if ( has_post_thumbnail() ) { $has_class = ''; } else { $has_class = ' no-thumb'; }
if( $count % 3 == 1 ) { echo '<div class="row">'; }
$code .= '<div class="post'.$post_class, $has_class.'" role="article" itemscope="" itemtype="http://schema.org/Article">
<div class="ws-meta">
<h3 itemprop="name" class="entry-title"><a itemprop="url" href="<'.get_permalink( $post->ID ).' rel="bookmark">'.the_title().'</a></h3>
</div>
</div>';
if( $count % 3 == 0 ) { echo "</div>\n"; }
$count++;
$i_cont++; endwhile; endif; wp_reset_postdata(); wp_reset_query();
if ( $count % 3 != 1 ) echo "</div>";
$code .= '</div>
</div>
</div>';
return $code;
}
add_shortcode( 'box_news_eight', 'box_news_eight' );
【问题讨论】:
-
get_the_category( ' ' );应该只是get_the_category();如果您要获取当前类别。这个函数只接受一个应该是整数的参数,目前你传入的是一个空字符串