0

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

5
  • Is this what you were looking for? wordpress.stackexchange.com/a/352780/124452
    – Anake.me
    Commented Apr 22, 2021 at 7:32
  • Hello, Thank you for your answer. No, the "Private" Item is normal, I don't have a publication date for this article yet. I fact, for my "Documentation" and "Actualités" pages, I want (in the header) to have these two titles and NOT the post title. "Contact" page on the menu have "Contact" title so that's what I want. Thanks for your help. Elisa
    – user205282
    Commented Apr 22, 2021 at 7:47
  • So the issue is that the title displays your last post title instead of the category title / page title?
    – Anake.me
    Commented Apr 22, 2021 at 7:54
  • @Anake.me Well, for example, I post an other answer about what I want. I let you check in case you can get an idea. Thank you ! Elisa
    – user205282
    Commented Apr 22, 2021 at 8:09
  • Have you tried using get_the_title()? You can add one more if statement stating that elseif( is_page('documentation') ) then add your h1 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

2 Answers 2

0

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.

2
  • AWESOME !! Thank you a lot ! I just modify "is_page()" by "in_category()" and it works :)
    – user205282
    Commented Apr 22, 2021 at 9:29
  • No worries! My apologies, I forgot you were using Categories haha! Please be sure to mark the answer as correct :) Happy coding!
    – Anake.me
    Commented Apr 22, 2021 at 9:38
0

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
}

?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.