WordPress啟用類別置頂插件category-sticky-post後,
類別內若無文章,會出現無貼文可置頂訊息:
Trying to get property of non-object in /.../wp-content/plugins/category-sticky-post/class-category-sticky-post.php on line 200
解法如下: 在add_styles()方法,增加isset($post->ID) && 判別指令。
category-sticky-post/class-category-sticky-post.php
public function add_styles() {
global $post;
if( isset($post->ID) && is_archive() && '1' !== get_post_meta( $post->ID, 'category_sticky_post_border', true ) ) {
wp_enqueue_style( 'category-sticky-post', plugins_url( '/category-sticky-post/css/plugin.css' ) );
}
}
參考:
https://tommcfarlin.com/category-sticky-post-2-1-0-support-post-types/
2016年9月22日 星期四
Trying to get property of non-object in /.../class-category-sticky-post.php on line 200
訂閱:
文章 (Atom)