目前,使用新网址将我的localhost网站更改为新域名。检查PHP日志并得到以下错误?
[06-Feb-2014 19:47:51] PHP解析错误:语法错误,意外'['in / var / www / ...第128行
这是我的代码:
<div class="home_story_container">
<a href="<?php echo get_permalink( $post->ID ); ?>"><div class="home_preview_photo" style="background-image:url('<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post- thumbnail' ); ?>
<?php echo $image[0]; ?>
<?php endif; ?>')">
</div></a>
<?php $category = get_the_category($post->ID)[0]->name; ?>
<?php
$category_link = get_category_link( get_cat_ID( $category ) );
?>
<a href="<?php echo esc_url( $category_link ); ?>"><span class="home_cat_tag"><?php echo $category; ?></span></a>
<br />
<a href="<?php echo get_permalink( $post->ID ); ?>"><span class="home_title"><?php echo get_the_title($post); ?></span></a>
<br /><br />
<span class="home_paragraph"><?php
$page_data = get_page( $post->ID );
echo strip_tags($page_data->post_excerpt);
?> – <a href="<?php echo get_permalink( $post->ID ); ?>">Read More »</a></span>
</div>
具体来说,我在这一行收到错误:
<?php $category = get_the_category($post->ID)[0]->name; ?>
有什么问题?
答案 0 :(得分:2)
PHP 5.4中引入了特定语法(function array dereferencing)。以前版本的PHP会将其标记为语法错误。
您可以使用PHP&lt; 5.4语法代替:
$categories = get_the_category($post->ID);
$category = $categories[0]->name;
答案 1 :(得分:0)
这应该可以解决您的问题,
<?php $category = get_the_category($post->ID);
$category = $category[0]->name; ?>