wordpress - 向所有博客页面添加操作
问题描述
我想为我的所有博客页面(主页/单篇文章/存档(标签、作者、类别等)都有一个特定的标题。
我已经设法定位博客的主页,但不是其余的(单个/档案):
function add_blog_header_single() {
// Echo out content
if ( is_home() && !is_front_page() ) {
echo
'<div id="blog-header"><p>
<img src="img.png" alt="">
</p></div>'
;
}
}
add_action( 'storefront_content_top' , 'add_blog_header_single', 20 );
我应该怎么办 ?
谢谢
解决方案
在这里,在您的主题 functions.php 文件中添加此代码。
function add_blog_header_single() {
$img_src = 'default-image.png'
if ( is_home() ) { // When the main blog page is being displayed.
$img_src = 'blog.png';
}
if( is_single() ) { // When a single post of any post type (except attachment and page post types) is being displayed.
$img_src = 'single-post.png';
}
if( is_archive() ) { // When any type of Archive page is being displayed. Category, Tag, other Taxonomy Term, custom post type archive, Author and Date-based pages are all types of Archives.
$img_src = 'archive.png';
}
echo '<div id="blog-header"><p> <img src="'.$img_src.'" alt=""></p></div>';
}
add_action( 'storefront_content_top' , 'add_blog_header_single', 20 );
推荐阅读
- python - 如何在 MultiListbox 中添加标签
- python - 如何将字典分解为python中的字典列表?
- javascript - 在 Chrome 中的多个元素上使用平滑函数的 scrollIntoView()
- discord.js - 我如何向有我的机器人注释的用户发送消息?
- php - 我使用 PHP/MySQL 作为后端创建了一个应用程序。基本 URL 不起作用
- python - 如何将字典值插入到 sql 表中?
- testing - 在 WebStorm 中为 CucumberJS 和基于 TestCafe 的项目调试配置
- c# - 如何拆分字符串并分配为表中的列和行
- spring - Thymeleaf 模型属性是否不允许以“is”开头?
- android - 发送短信时一加设备问题