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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
How 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 strings.
Method 2
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
}
?>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0