しばらく前から時々出るエラーが気になっていた。single.phpのline4が「PHP Catchable fatal error: Object of class WP_Error could not be converted to strin」となる。パンくずリスト部分、別の書き方に修正してみる。
以前のもの
<a href="<?php bloginfo('url'); ?>">TOP</a> > <?php $cat = get_the_category(); echo get_category_parents($cat[0], true, ' > '); ?><?php the_title(''); ?>
このエラー、記事ページから画像をクリックしたときの画像ページで出ていることが判明(他ページでも出ているかは不明)。
検証にFlickrから埋め込んだアイキャッチ画像をクリックすると、以前はエラーログが表示されたのが、このたびはFlickrの404Not Foundページとなる。記事ページから不要と思われるスクリプトと埋め込みタグを削除し、シンプルな**.jpgのURLをリンクとソースで同じにしてみた。と、LiteBoxが開くようになった。これでいいけれど、毎回手動で削除しなくちゃいけない?
以下に修正
<?php $postcate = get_the_category(); ?>
<a href="<?php echo home_url(); ?>">TOP</a> >
<?php echo get_category_parents($postcate[0]->term_id,TRUE,' > '); ?>
<?php the_title(''); ?>ついでにリンクのborder-bottomの波線を消すCSSを追加。<p style=”img”>
テーマの更新:2.1.2 ➾ 2.3.1
– ウィジェットのHome1がLiteにも追加された。(リモートは更新まだ)
➾ テーマカスタマイズの記事も修正すること
4/15日
ほとんど毎日出ていた PHP Catchable fatal error: … が今日は出ていない。
コードを書き変えたせいか、それともFlickrの埋め込みを単なる画像リンクに修正したためかは不明。
Flickrの404は単にアルバムのパーミッションの問題だったことが判明。
その後
やはりエラーログが出る。
結局以下を functions.php に書き込み、必要な個所にコードを追加する、という方法に落ち着いた。
function breadcrumb(){global $post;$str ='';if(!is_home()&&!is_admin()){$str.= '<div class="breadcrumb"><span itemscope itemtype="http://data-vocabulary.org/Breadcrumb">';$str.= '<a href="'. home_url() .'" itemprop="url"><span itemprop="title"><i class="fa fa-home"></i> TOP</span></a> > </span>';if(is_category()) {$cat = get_queried_object();if($cat -> parent != 0){$ancestors = array_reverse(get_ancestors( $cat -> cat_ID, 'category' ));foreach($ancestors as $ancestor){$str.='<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="'. get_category_link($ancestor) .'" itemprop="url"><span itemprop="title">'. get_cat_name($ancestor) .'</span></a> > </span>';}}$str.='<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="'. get_category_link($cat -> term_id). '" itemprop="url"><span itemprop="title">'. $cat-> cat_name . '</span></a> > </span>';} elseif(is_page()){if($post -> post_parent != 0 ){$ancestors = array_reverse(get_post_ancestors( $post->ID ));foreach($ancestors as $ancestor){$str.='<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="'. get_permalink($ancestor).'" itemprop="url"><span itemprop="title">'. get_the_title($ancestor) .'</span></a> > </span>';}}} elseif(is_single()){$categories = get_the_category($post->ID);$cat = $categories[0];if($cat -> parent != 0){$ancestors = array_reverse(get_ancestors( $cat -> cat_ID, 'category' ));foreach($ancestors as $ancestor){$str.='<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="'. get_category_link($ancestor).'" itemprop="url"><span itemprop="title">'. get_cat_name($ancestor). '</span></a> > </span>';}}$str.='<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="'. get_category_link($cat -> term_id). '" itemprop="url"><span itemprop="title">'. $cat-> cat_name . '</span></a> > </span>';} else{$str.='<div>'. wp_title('', false) .'</div><br/>';}$str.='</div>';}echo $str;}
single.php のパンくずリストを表示させたい位置(ヘッダー下など)に以下のコードを追加する。
<?php breadcrumb(); ?>
いくつか参考にさせていただいたサイトがあったのだが、時間がたってしまい、記憶を紛失…。




コメント