在Wordpress中有没有更简单的方法来做到这一点?
我想要做的是根据显示不同图像的页面/帖子用户来更改header类。
我的代码- PHP
<?php
//Services page
if ( is_page( 'services' ) ) {
echo'<header class="main_top services_page">';
}
//Portfolio page
else if ( is_page( 'portfolio' ) ) {
echo'<header class="main_top portfolio_page">';
}
//Digital page
else if ( is_single( 'digital' ) ) {
echo'<header class="main_top digital_page">';
}
//Social Media page
else if ( is_single( 'social-media-2' ) ) {
echo'<header class="main_top media_page">';
}
//Print page
else if ( is_single( 'print' ) ) {
echo'<header class="main_top print_page">';
}
//Home page
else echo'<header class="main_top">';
?>我为每个头类添加了一个不同的CSS类,如下所示
header.services_page{
background-image: url(images/contentmarketing1-2000x450.jpg);
}
header.portfolio_page{
background-image: url(images/portfolio-2000x450.jpg);
}
header.contact_page{
background-image: url(images/contact-2000x450.jpg);
}
header.digital_page{
background-image: url(images/digital2-2000x450.jpg);
}
header.media_page{
background-image: url(images/socialmedia-2000x450.jpg);
}
header.print_page{
background-image: url(images/print-2000x450.jpg);
}
header.audio_page{
background-image: url(images/audio-2000x450.jpg);
}
header.pr_page{
background-image: url(images/pr-2000x450.jpg);
}
header.cm_page{
background-image: url(images/contentmarketing2-2000x450.jpg);
}谢谢!:-)
发布于 2014-03-10 19:16:02
$page_post_title=get_the_title($page_post_ID);
echo'<header class="main_top $page_post_title">';这将在一行中完成。
试一下,或者你也可以修改它。
https://stackoverflow.com/questions/22298441
复制相似问题