【问题标题】:Wordpress php and htmlWordPress php 和 html
【发布时间】:2015-11-20 21:15:34
【问题描述】:

Sublime text 显示错误,当我检查网络浏览器时,这条线错了吗?但我看不到错误 行开始 $output .= '

<article class="post">
    <h2><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h2>

    <p class="post-info"><?php the_time('F j, Y G:i '); ?> | by <a href="<?php echo get_author_posts_url( get_the_author_meta('ID')); ?>"><?php the_author(); ?></a>| Posted in 

        <?php

        $categories = get_the_category( );
        $separator = ", ";
        $output = '';

        if ($categories){

            foreach ($categories as $category ) {

             $output .= '<a href="' . get_the_category_link($category->term_id) . '">' . $category->cat_name . '</a>' . $separator;

            }

            echo trim($output, $separator);
        }

        ?>

        </p> 

    <?php the_content(); ?> 
</article>  

<?php endwhile;

else :
    echo '<p>No content found</p>';

endif;

get_footer();

?>

【问题讨论】:

  • 添加我们是否应该猜测错误是什么?
  • 你能把错误贴出来让我们看看它说了什么吗?
  • Sublime 文本标记了这一行的 term_id) . '">' 。 $category->cat_name 。 '' 。 $分隔符;我现在不知道为什么?但是在浏览器上出现致命错误:调用未定义的函数get_the_category_link()。我是新手,但希望我能尽可能地解释它。感谢我能得到的所有帮助
  • 你得到的错误是因为函数 'get_the_catgory_link' 实际上不是 Wordpress 函数。我认为您正在寻找的可能是get_category_link()
  • 最后,问题解决了......如果我使用 get_category_link 而不是...... get_the_category 链接它可以工作。

标签: php html wordpress


【解决方案1】:

正如您所说,您收到以下错误。

致命错误:在...中调用未定义的函数 get_the_category_link()

这意味着你调用的函数没有定义(PHP 不知道你想让它对这个函数做什么)。

我认为您只是使用了错误的函数名称。您想使用此 'get_category_link() 而不是 get_the_category_link()。 Wordpress 已经为您定义了get_category_link() 函数,因此您不应该得到未定义函数错误。

【讨论】:

    猜你喜欢
    • 2020-10-06
    • 1970-01-01
    • 2013-05-28
    • 1970-01-01
    • 2020-11-09
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    相关资源
    最近更新 更多