这个问题可能有简单的答案,但我不是一个专业的程序员,所以让我按时间顺序解释我的问题。
我为每个帖子应用自定义样式,它使用以下方法工作。但当我想在主页上显示我的最新帖子(包括其自定义样式)时,我遇到了麻烦。我想要的结果,你可以看到Trent Walton\'s Blog 供参考。
This is my method for custom style on every post:
//Custom CSS Widget add_action(\'admin_menu\', \'custom_css_hooks\'); add_action(\'save_post\', \'save_custom_css\'); add_action(\'wp_head\',\'insert_custom_css\'); function custom_css_hooks() { add_meta_box(\'custom_css\', \'Custom Styles\', \'custom_css_input\', \'post\', \'normal\', \'high\'); add_meta_box(\'custom_css\', \'Custom Styles\', \'custom_css_input\', \'page\', \'normal\', \'high\'); } function custom_css_input() { global $post; echo \'\'; echo \'\'.get_post_meta($post->ID,\'_custom_css\',true).\'\'; } function save_custom_css($post_id) { if (!wp_verify_nonce($_POST[\'custom_css_noncename\'], \'custom-css\')) return $post_id; if (defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) return $post_id; $custom_css = $_POST[\'custom_css\']; update_post_meta($post_id, \'_custom_css\', $custom_css); } function insert_custom_css() { if (is_page() || is_single()) { if (have_posts()) : while (have_posts()) : the_post(); echo \' \'.get_post_meta(get_the_ID(), \'_custom_css\', true).\' \'; endwhile; endif; rewind_posts(); } }我在自定义字段中添加了一些样式。
和我的风格在自定义字段这将被注入到标题的单一职位。我工作。
On homepage (by creating home.php) I put my latest post, with this:
get_header(); ...loop to show the same content as latest single.. get_footer();我的主页显示了我想要的最新帖子,但问题是its custom style not included.
Then I try to modify my conditional tags (fro showing custom style):发件人
function insert_custom_css() { if (is_page() || is_single()) { ... } }至
function insert_custom_css() { if (is_home() || is_page() || is_single()) { ... } }结果很糟糕,它没有显示当前显示的帖子的自定义样式。The home post is now styled with my first post custom style.
我正在寻求你的帮助,谢谢。