WordPress的每页不同的标题图像 [英] Wordpress different header image for each page

查看:60
本文介绍了WordPress的每页不同的标题图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过插件尝试时,我的主题不支持自定义标头,因此我想知道是否还有另一种方法?

My theme doesn't support custom headers when trying via a plugin so i was wondering if there was another way around this?

通过在header.php中添加一些代码来测试WP标头图像,但似乎不起作用.

Tested WP Header Images by adding some code in header.php, but doesn't seem to work.

尝试了插件唯一标头",但是会弹出一条消息,提示主题在激活时不提供自定义标头.

Tried the plugin Unique Headers, but it pops a message that the theme doesn't provide custom header when activating it.

推荐答案

默认情况下,网站的每个WordPress页面都有相同的标题.但是,如何在WordPress中调用不同的标头?为此,请创建一个新的header-page.php文件,即为您想要其他标题的页面创建一个标题文件.假设您要在About页面上使用其他标题.创建header-about.php文件,并将其保存在Theme文件夹中.

By default, there is the same header for every WordPress page of the site. But how to call different header in WordPress? For that, create a new header-your page.php file i.e create a header file for the page you want a different header. Suppose you want a different header on about page. Create a header-about.php file and keep it in the Theme folder.

然后,进入页面模板文件,例如page.php,并将标头代码替换为

Then, go in page template file say page.php and replace the header code with

<?php
if(is_page(about))
{
get_header('about');
}
else
{
get_header();
}
wp_head();
?>

您可以看到,is_page用于检查关于"页面的页面ID.函数get_header用于调用新的头文件.简而言之,以上代码告诉WordPress,如果有人打开页面"about",那么WordPress将显示一个名为header-about.php的文件(如果存在).如果不是,则WordPress将呈现默认的头文件.

You can see, is_page is used to check the page id for "about" page. The function get_header is used for calling a new header file. Simply, the above code is informing WordPress that if someone opens the page, which is ‘about’ then WordPress will display a file called header-about.php if it is existing. If not, then WordPress will render the default header file.

这样,您可以在不同页面上调用不同的WordPress标头.

This way, you can call different WordPress headers on different pages.

这篇关于WordPress的每页不同的标题图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆