質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

1回答

420閲覧

「ashe」というテーマでエラーメッセージ表示

wwjikk

総合スコア12

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2019/07/15 04:24

編集2019/07/15 04:35

実現したいこと

ナビゲーションに当てられているのですが、なぜか
エラー表示が出てしまいます。どなたかお力かしていただけますか?

エラーメッセージ

Warning: sprintf(): Too few arguments in /home/aquaokapi3/www/wproot/wp-includes/nav-menu-template.php on line 261

ソースコード

php

1<?php 2/** 3 * Nav Menu API: 4 * 5 * @package WordPress 6 * @subpackage Nav_Menus 7 * @since 3.0.0 8 */ 9 10/** Walker_Nav_Menu class */ 11require_once ABSPATH . WPINC . '/class-walker-nav-menu.php'; 12 13/** 14 * Displays a navigation menu. 15 * 16 * @since 3.0.0 17 * @since 4.7.0 Added the `item_spacing` argument. 18 * 19 * @staticvar array $menu_id_slugs 20 * 21 * @param array $args { 22 * Optional. Array of . 23 * 24 * @type int|string|WP_Term $menu Desired menu. Accepts a menu ID, slug, name, or object. Default empty. 25 * @type string $menu_class CSS class to use for the ul element which forms the menu. Default 'menu'. 26 * @type string $menu_id The ID that is applied to the ul element which forms the menu. 27 * Default is the menu slug, incremented. 28 * @type string $container Whether to wrap the ul, and what to wrap it with. Default 'div'. 29 * @type string $container_class Class that is applied to the container. Default 'menu-{menu slug}-container'. 30 * @type string $container_id The ID that is applied to the container. Default empty. 31 * @type callable|bool $fallback_cb If the menu doesn't exists, a callback function will fire. 32 * Default is 'wp_page_menu'. Set to false for no fallback. 33 * @type string $before Text before the link markup. Default empty. 34 * @type string $after Text after the link markup. Default empty. 35 * @type string $link_before Text before the link text. Default empty. 36 * @type string $link_after Text after the link text. Default empty. 37 * @type bool $echo Whether to echo the menu or return it. Default true. 38 * @type int $depth How many levels of the hierarchy are to be included. 0 means all. Default 0. 39 * @type object $walker Instance of a custom walker class. Default empty. 40 * @type string $theme_location Theme location to be used. Must be registered with register_nav_menu() 41 * in order to be selectable by the user. 42 * @type string $items_wrap How the list items should be wrapped. Default is a ul with an id and class. 43 * Uses printf() format with numbered placeholders. 44 * @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. Default 'preserve'. 45 * } 46 * @return string|false|void Menu output if $echo is false, false if there are no items or no menu was found. 47 */ 48function wp_nav_menu( $args = array() ) { 49 static $menu_id_slugs = array(); 50 51 $defaults = array( 52 'menu' => '', 53 'container' => 'div', 54 'container_class' => '', 55 'container_id' => '', 56 'menu_class' => 'menu', 57 'menu_id' => '', 58 'echo' => true, 59 'fallback_cb' => 'wp_page_menu', 60 'before' => '', 61 'after' => '', 62 'link_before' => '', 63 'link_after' => '', 64 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 65 'item_spacing' => 'preserve', 66 'depth' => 0, 67 'walker' => '', 68 'theme_location' => '', 69 ); 70 71 $args = wp_parse_args( $args, $defaults ); 72 73 if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) { 74 // invalid value, fall back to default. 75 $args['item_spacing'] = $defaults['item_spacing']; 76 } 77 78 /** 79 * Filters the arguments used to display a navigation menu. 80 * 81 * @since 3.0.0 82 * 83 * @see wp_nav_menu() 84 * 85 * @param array $args Array of wp_nav_menu() arguments. 86 */ 87 $args = apply_filters( 'wp_nav_menu_args', $args ); 88 $args = (object) $args; 89 90 /** 91 * Filters whether to short-circuit the wp_nav_menu() output. 92 * 93 * Returning a non-null value to the filter will short-circuit 94 * wp_nav_menu(), echoing that value if $args->echo is true, 95 * returning that value otherwise. 96 * 97 * @since 3.9.0 98 * 99 * @see wp_nav_menu() 100 * 101 * @param string|null $output Nav menu output to short-circuit with. Default null. 102 * @param stdClass $args An object containing wp_nav_menu() arguments. 103 */ 104 $nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args ); 105 106 if ( null !== $nav_menu ) { 107 if ( $args->echo ) { 108 echo $nav_menu; 109 return; 110 } 111 112 return $nav_menu; 113 } 114 115 // Get the nav menu based on the requested menu 116 $menu = wp_get_nav_menu_object( $args->menu ); 117 118 // Get the nav menu based on the theme_location 119 if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) ) { 120 $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] ); 121 } 122 123 // get the first menu that has items if we still can't find a menu 124 if ( ! $menu && ! $args->theme_location ) { 125 $menus = wp_get_nav_menus(); 126 foreach ( $menus as $menu_maybe ) { 127 if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { 128 $menu = $menu_maybe; 129 break; 130 } 131 } 132 } 133 134 if ( empty( $args->menu ) ) { 135 $args->menu = $menu; 136 } 137 138 // If the menu exists, get its items. 139 if ( $menu && ! is_wp_error( $menu ) && ! isset( $menu_items ) ) { 140 $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); 141 } 142 143 /* 144 * If no menu was found: 145 * - Fall back (if one was specified), or bail. 146 * 147 * If no menu items were found: 148 * - Fall back, but only if no theme location was specified. 149 * - Otherwise, bail. 150 */ 151 if ( ( ! $menu || is_wp_error( $menu ) || ( isset( $menu_items ) && empty( $menu_items ) && ! $args->theme_location ) ) 152 && isset( $args->fallback_cb ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) { 153 return call_user_func( $args->fallback_cb, (array) $args ); 154 } 155 156 if ( ! $menu || is_wp_error( $menu ) ) { 157 return false; 158 } 159 160 $nav_menu = $items = ''; 161 162 $show_container = false; 163 if ( $args->container ) { 164 /** 165 * Filters the list of HTML tags that are valid for use as menu containers. 166 * 167 * @since 3.0.0 168 * 169 * @param array $tags The acceptable HTML tags for use as menu containers. 170 * Default is array containing 'div' and 'nav'. 171 */ 172 $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); 173 if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags ) ) { 174 $show_container = true; 175 $class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-' . $menu->slug . '-container"'; 176 $id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : ''; 177 $nav_menu .= '<' . $args->container . $id . $class . '>'; 178 } 179 } 180 181 // Set up the $menu_item variables 182 _wp_menu_item_classes_by_context( $menu_items ); 183 184 $sorted_menu_items = $menu_items_with_children = array(); 185 foreach ( (array) $menu_items as $menu_item ) { 186 $sorted_menu_items[ $menu_item->menu_order ] = $menu_item; 187 if ( $menu_item->menu_item_parent ) { 188 $menu_items_with_children[ $menu_item->menu_item_parent ] = true; 189 } 190 } 191 192 // Add the menu-item-has-children class where applicable 193 if ( $menu_items_with_children ) { 194 foreach ( $sorted_menu_items as &$menu_item ) { 195 if ( isset( $menu_items_with_children[ $menu_item->ID ] ) ) { 196 $menu_item->classes[] = 'menu-item-has-children'; 197 } 198 } 199 } 200 201 unset( $menu_items, $menu_item ); 202 203 /** 204 * Filters the sorted list of menu item objects before generating the menu's HTML. 205 * 206 * @since 3.1.0 207 * 208 * @param array $sorted_menu_items The menu items, sorted by each menu item's menu order. 209 * @param stdClass $args An object containing wp_nav_menu() arguments. 210 */ 211 $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args ); 212 213 $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args ); 214 unset( $sorted_menu_items ); 215 216 // Attributes 217 if ( ! empty( $args->menu_id ) ) { 218 $wrap_id = $args->menu_id; 219 } else { 220 $wrap_id = 'menu-' . $menu->slug; 221 while ( in_array( $wrap_id, $menu_id_slugs ) ) { 222 if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) { 223 $wrap_id = preg_replace( '#-(\d+)$#', '-' . ++$matches[1], $wrap_id ); 224 } else { 225 $wrap_id = $wrap_id . '-1'; 226 } 227 } 228 } 229 $menu_id_slugs[] = $wrap_id; 230 231 $wrap_class = $args->menu_class ? $args->menu_class : ''; 232 233 /** 234 * Filters the HTML list content for navigation menus. 235 * 236 * @since 3.0.0 237 * 238 * @see wp_nav_menu() 239 * 240 * @param string $items The HTML list content for the menu items. 241 * @param stdClass $args An object containing wp_nav_menu() arguments. 242 */ 243 $items = apply_filters( 'wp_nav_menu_items', $items, $args ); 244 /** 245 * Filters the HTML list content for a specific navigation menu. 246 * 247 * @since 3.0.0 248 * 249 * @see wp_nav_menu() 250 * 251 * @param string $items The HTML list content for the menu items. 252 * @param stdClass $args An object containing wp_nav_menu() arguments. 253 */ 254 $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args ); 255 256 // Don't print any markup if there are no items at this point. 257 if ( empty( $items ) ) { 258 return false; 259 } 260 $nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items ); 261 unset( $items ); 262 263

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

sprintf()においてToo few arguments (引数が少なすぎる)というのは下記のようなケースになります。

php

1<?php 2echo sprintf("%s %s %s","a","b");

3つ受け口があるのに2つしかつけてないということですね。

ちなみにnullでも入ればOKです。

php

1<?php 2echo sprintf("%s %s %s","a","b",null);

多くてもエラーにはなりません。

php

1<?php 2echo sprintf("%s %s %s","a","b",null,null);

で、提示コードだと第一引数$args->items_wrapの内容は下記ですかね
<ul id="%1$s" class="%2$s">%3$s</ul>

番号が当てられているように3つの引数を求めています。

php

1$nav_menu .= sprintf( $args->items_wrap 2, esc_attr( $wrap_id ) //1 3, esc_attr( $wrap_class ) //2 4, $items ); //3

3つ入っているように見えます。

・・・となると

怪しいのは下記

php

1$args = wp_parse_args( $args, $defaults );

WordPress私的マニュアル/wp parse args

クエリー文字列を解析し、各パラメータのデフォルト値とマージした連想配列を取得する

「マージ」なのですが、重複したキーがあった場合は$argsのほうが残るようです。

パラメータ$argsに'post=44&action=edit'、$defaultsがarray( 'post'=>0,'action'='new', 'post_type'=>'post' )の場合、この関数の戻り値は次のようになる。

array( 'post' => 44, 'action' => 'edit', 'post_type' => 'post' )

と、いうことはwp_nav_menu()の引数$argsにitems_wrapというキーが設定されており、defaultのitems_wrapに指定されている引数より多くの引数が設置されている、と考えられます。

まずは$args->items_wrapの内容をvar_dump()で確認し、どのような値になっているかで対策を決めましょう。

※ただ、提示されたコードがasheというテーマのファイルの一部で自身が何も組んでいないものでしたらテーマのアップデートで改善されるかもしれません。
アップデートで解決しなければテーマの開発元に問い合わせてみましょう。

投稿2019/08/30 03:19

m.ts10806

総合スコア80850

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問