警告:sprintf():functions.php中的参数太少

问题描述 投票:0回答:1

我在自定义breadcrumb函数中收到此PHP错误:

警告:sprintf():第151行/srv/bindings/56058a57d7424f84adac37ba6b03d3b7/code/wp-content/themes/inspire-spine/functions.php中的参数太少

这是代码:

if ( is_page() && $parent_id ) {
    if ($parent_id != $frontpage_id) {
        $breadcrumbs = array();
        while ($parent_id) {
            $page = get_page($parent_id);
            if ($parent_id != $frontpage_id) {
                $breadcrumbs[] = sprintf($link, get_permalink($page->ID)); //, get_the_title($page->ID));
            }
            $parent_id = $page->post_parent;
        }
        $breadcrumbs = array_reverse($breadcrumbs);
        for ($i = 0; $i < count($breadcrumbs); $i++) {
            echo $breadcrumbs[$i];
            if ($i != count($breadcrumbs)-1) echo $delimiter;
        }
    }
    if ($show_current == 1) {
        if ($show_home_link == 1 || ($parent_id_2 != 0 && $parent_id_2 != $frontpage_id)) echo $delimiter;
        echo $before . get_the_title() . $after;
    }

}

我在第7行得到错误,我错过了什么?

php wordpress function
1个回答
1
投票

你的sprintf字符串有2个占位符,你的填充符。

<?php
// bad
echo sprintf('<a href="%1$s">%2$s</a>', 'http://example.com');

// good
echo sprintf('<a href="%1$s">%2$s</a>', 'http://example.com', 'Link Name');

https://3v4l.org/nu8Ht

© www.soinside.com 2019 - 2024. All rights reserved.