操作
サポート #2602
完了
アデ
廣僚
検索結果が存在しない場合にWarningエラーが表示される不具合
サポート #2602:
検索結果が存在しない場合にWarningエラーが表示される不具合
説明
指示内容¶
水族館サイトにおいて、サイト検索で検索結果が存在しない場合にPHP Warningエラーが画面上に表示される不具合を確認。
/home/chitose-aq/chitose-aq.jp/public_html/dev/wp/wp-content/themes/cld/inc/func_com.php on line 595
Warning: Attempt to read property "post_parent" on null in /home/chitose-aq/chitose-aq.jp/public_html/dev/wp/wp-content/themes/cld/inc/func_com.php on line 603
https://dev.chitose-aq.jp/wp/wp-content/themes/cld/assets/img/title.jpg" class="img-fluid d-block mx-auto w-100" alt="" />
アデ アルドリノ デフリン さんが26日前に更新
- 題名 を 検索結果がない時にWarningエラーが表示される不具合 から 検索結果が存在しない場合にWarningエラーが表示される不具合 に変更
- 説明 を更新 (差分)
アデ アルドリノ デフリン さんが26日前に更新
- ステータス を 新規 から 進行中 に変更
- 進捗率 を 0 から 30 に変更
アデ アルドリノ デフリン さんが26日前に更新
原因¶
ヘッダー画像を取得する関数でグローバル投稿を使用しており
検索結果が存在しない場合に $post が空のためエラーが出力されています。
対処¶
$post が存在有無の検証を追加し、なければデフォルト画像を出力するように修正。
修正前¶
function get_header_img()
{
// Get the current page slug
global $post;
$slug = $post->post_name;
// Get the parent page slug if exists
$parent_slug = $post->post_parent ? get_post($post->post_parent)->post_name : '';
$slug_image = "title-$slug.jpg";
$parent_slug_image = $parent_slug ? "title-$parent_slug.jpg" : '';
$default_image = 'title.jpg';
// 略
}
修正後¶
function get_header_img()
{
// Paths to check
$base_path = get_template_directory() . '/assets/img/';
$base_url = get_template_directory_uri() . '/assets/img/';
$default_image = 'title.jpg';
// Get the current page slug
global $post;
// 存在しない場合にデフォルト画像を返すように追加
if (!$post) {
return $base_url . $default_image;
}
$slug = $post->post_name;
// Get the parent page slug if exists
$parent_slug = $post->post_parent ? get_post($post->post_parent)->post_name : '';
// 略
}
アデ アルドリノ デフリン さんが26日前に更新
- ステータス を 進行中 から フィードバック に変更
- 担当者 を アルドリノ デフリン から 廣瀬 僚一 に変更
- 進捗率 を 30 から 50 に変更
操作