本文介绍了警告:sprintf():functions.php中的参数太少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在自定义面包屑函数中遇到此PHP错误:
I'm getting this PHP error in my custom breadcrumb function:
这是代码:
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行中得到错误,我想念什么?
I get the error in line 7, what am I missing?
推荐答案
您的 sprintf 字符串有2个占位符,您占了1个.
Your sprintf string has 2 placeholders, your filling one.
<?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');
这篇关于警告:sprintf():functions.php中的参数太少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!