当我尝试单击WordPress帖子的作者姓名时,为什么我会收到此错误消息?

时间:2014-02-12 17:55:50

标签: php content-management-system wordpress-theming wordpress

我是WordPress主题开发的新手,我在这个我正在开发的自定义主题中遇到了一个奇怪的行为:http://onofri.org/WP_BootStrap/

正如您在博客中看到的那样,会显示2个帖子,每篇帖子的开头都会打印作者姓名(在本例中为 admin )。

现在,如果您打印此作者姓名(在“通过管理”链接上),您可以看到 admin <已写入的帖子/ strong>用户,这是正确的行为

问题是,如果我尝试在我的本地版本的网站上执行相同的操作(主题完全相同),我会收到以下错误消息:

notice:%20Undefined%20variable:%20authordata%20in%20/var/www/wordpress/wp-content/themes/AsperTheme/content.php%20on%20line%2032Notice:%20Trying%20to%20get%20property%20of%20non-object%20in%20/var/www/wordpress/wp-content/themes/AsperTheme/content.php%20on%20line%2032Notice:%20Undefined%20variable:%20authordata%20in%20/var/www/wordpress/wp-content/themes/AsperTheme/content.php%20on%20line%2032Notice:%20Trying%20to%20get%20property%20of%20non-object%20in%20/var/www/wordpress/wp-content/themes/AsperTheme/content.php%20on%20line%2032Notice:%20get_author_link%20is%20<strong>deprecated</strong>%20since%20version%202.1!%20Use%20get_author_posts_url%28%29%20instead.%20in%20/var/www/wordpress/wp-includes/functions.php%20on%20line%202908http://localhost/wordpress/author/

这是我的 content.php 文件的代码:

/**
 * The default template for displaying content
 *
 * Used for both single and index/archive/search.
 *
 * @package WordPress
 * @subpackage AsperTheme
 * @since AsperTheme 1.0
 */
?>


<!-- Create a div with a unique ID thanks to the_ID() and semantic classes with post_class() 
     the_ID(): Print the numeric ID of the current post 
     post_class(): Print out and add various post-related classes to the div tag
-->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>                              

    <header>
        <h3 class="entry-title">
                <a href="<?php the_permalink(); ?>" 
                   title="<?php printf(__('Permalink to %s', 'your-theme'), the_title_attribute('echo=0')); ?>"
                   rel="bookmark"><?php the_title(); ?>
                </a>

        </h3>

        <div class="entry-meta">
            <span class="meta-prep meta-prep-author"><?php _e('By ', 'your-theme'); ?></span>
            <span class="author vcard">
                <a class="url fn n" href="<?php echo get_author_link(false, $authordata -> ID, $authordata -> user_nicename); ?>" 
                                    title="<?php printf(__('View all posts by %s', 'your-theme'), $authordata -> display_name); ?>"><?php the_author(); ?>
                </a>
            </span>
            <span class="meta-sep"> | </span>
            <span class="meta-prep meta-prep-entry-date"><?php _e('Published ', 'your-theme'); ?></span>
            <span class="entry-date">
                <abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time(get_option('date_format')); ?></abbr>
            </span>
            <?php edit_post_link( __( 'Edit', 'your-theme' ), "<span class=\"meta-sep\">|</span>\n\t\t\t\t\t\t<span class=\"edit-link\">", "</span>\n\t\t\t\t\t" ) ?>
         </div>     <!-- .entry-meta -->

    </header>

    <div class="entry-content">    
        <?php the_content(__('Continue reading <span class="meta-nav">&raquo;</span>', 'your-theme')); ?>
        <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'your-theme' ) . '&after=</div>') ?>
    </div>      <!-- .entry-content -->

    <div class="entry-utility">
        <span class="cat-links">
            <span class="entry-utility-prep entry-utility-prep-cat-links"><?php _e('Posted in ', 'your-theme'); ?></span>
            <?php echo get_the_category_list(', '); ?>
        </span>
        <span class="meta-sep"> | </span>
        <?php the_tags( '<span class="tag-links"><span class="entry-utility-prep entry-utility-prep-tag-links">' . __('Tagged ', 'your-theme' ) . '</span>', ", ", "</span>\n\t\t\t\t\t\t<span class=\"meta-sep\">|</span>\n" ) ?>
            <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'your-theme' ), __( '1 Comment', 'your-theme' ), __( '% Comments', 'your-theme' ) ) ?></span>
            <?php edit_post_link( __( 'Edit', 'your-theme' ), "<span class=\"meta-sep\">|</span>\n\t\t\t\t\t\t<span class=\"edit-link\">", "</span>\n\t\t\t\t\t\n" ) ?>
    </div>      <!-- #entry-utility --> 

</article>  <!-- #post-<?php the_ID(); ?> -->

为什么呢?可能是什么问题?

TNX

安德烈

1 个答案:

答案 0 :(得分:0)

您没有声明变量“$ AuthorData”。 第32行第一次使用作为对象,但值为“null”。 抱歉我的英文,请使用谷歌翻译