admin管理员组文章数量:1294533
In order to have two blogs on one website, I was able to put in the menu two categories: DOCUMENTATION and ACTUALITES. My problem is in the header. The titles are displayed well however for both categories, the titles correspond to the title of the last article of the page... You can see an example in the picture (You will see that the CONTACT page is OK but for the DOCUMENTATION and ACTUALITES pages the titles are those of the last article). I would like to replace these article titles with those of the DOCUMENTATION and ACTUALITES categories. I think I have found the problem code but I don't know how to solve it.
<?php
if ( is_front_page() )
{
?>
<div class="bloc-header-home">
<span class="decouvrez">Découvrez</span>
<h1>La chasse</h1>
<span class="avantages">Text description</span>
<a href="<?php echo get_page_link(221); ?>"><button class="header__see-more">en savoir plus</button></a>
</div>
<?php
}
elseif ( is_home() ) {
?>
<h1>Actualités</h1>
<?php
}
else {
?>
<h1><?php the_title(); ?></h1>
<?php
}
?>
Could someone help me? Thanks in advance for your help! Els
In order to have two blogs on one website, I was able to put in the menu two categories: DOCUMENTATION and ACTUALITES. My problem is in the header. The titles are displayed well however for both categories, the titles correspond to the title of the last article of the page... You can see an example in the picture (You will see that the CONTACT page is OK but for the DOCUMENTATION and ACTUALITES pages the titles are those of the last article). I would like to replace these article titles with those of the DOCUMENTATION and ACTUALITES categories. I think I have found the problem code but I don't know how to solve it.
<?php
if ( is_front_page() )
{
?>
<div class="bloc-header-home">
<span class="decouvrez">Découvrez</span>
<h1>La chasse</h1>
<span class="avantages">Text description</span>
<a href="<?php echo get_page_link(221); ?>"><button class="header__see-more">en savoir plus</button></a>
</div>
<?php
}
elseif ( is_home() ) {
?>
<h1>Actualités</h1>
<?php
}
else {
?>
<h1><?php the_title(); ?></h1>
<?php
}
?>
Could someone help me? Thanks in advance for your help! Els
Share Improve this question edited Apr 22, 2021 at 10:12 user205282 asked Apr 22, 2021 at 7:18 user205282user205282 32 bronze badges 5 |2 Answers
Reset to default 0How about extending the if
statement to include the pages you require?
Your code would look something like this:
<?php
if( is_front_page() ) { ?>
<div class="bloc-header-home">
<span class="decouvrez">Découvrez</span>
<h1>La chasse en licence</h1>
<span class="avantages">La chasse est partie prenante de la gestion durable des forêts, car elle contribue à la conservation des écosystèmes forestiers et au développement de leur biodiversité. <br />Découvrez les avantages des chasses en licence dans les territoires d’exception.</span>
<a href="<?php echo get_page_link(221); ?>"><button class="header__see-more">en savoir plus</button></a>
</div>
<?php } elseif( is_page( 'Actualités' ) ) { ?>
<h1>Actualités</h1>
<?php } elseif( is_page( 'Documentation' ) ) { ?>
<h1>Documentation</h1>
<?php } else { ?>
<h1><?php the_title(); ?></h1>
<?php }
?>
This link will help you understand the is_page()
function and it's abilities to use both ID's int
and page names / slugs string
s.
Ok guys, I found a first solution to my problem BUT now I have to fix an other one...
here is what I started to do :
<?php
}
elseif ( is_home() ) {
?>
<h1>Actualités</h1>
<?php
}
else {
?>
<!-- TEST WITHOUT <h1><?php the_title(); ?></h1>--> <h1><?php single_cat_title(); ?></h1>
<?php
}
?>
本文标签: Posts title instead of Pages and Category titlesPHP Wordpress
版权声明:本文标题:Posts title instead of Pages and Category titles - PHP Wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741601906a2387750.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_the_title()
? You can add one moreif
statement stating thatelseif( is_page('documentation') )
then add yourh1
tag? You can also use page ID's instead of the page name if that is easier for you! – Anake.me Commented Apr 22, 2021 at 8:49