On mobile, I want to display what page my users are on. I have 6 top pages at the moment.
Home, Projects, Blog, Contact, Privacy Policy and Impressum. Both Projects and Blog have posts in them. Projects is a custom post type as well.
When a user clicks on Contact, title should change to contact. If they go to Project and click on a post, the title should say projects. I hope I make it clear.
I don't mind working with if
statements either if that's a solution.
Here is an image of what it would look like:
I hope I am making myself clear. Does anyone have a solution?
I have tried it with get_the_title()
to echo the title, but this does not give me proper results. When I'm on my Contact Page, it does say Contact. But once I'm on my home, project or blog page, it gives me the title of some post item, and not the title of the page as I want.
To give more context of what I want:
Imagine it like a breadcrumb, but instead, I only want one part of it. So instead of
Home > Contact
or
Home > Project > Some Post Title
I want only "Contact" or "Project". How would I go about that?
So now I have this code:
if ( is_front_page() ) {
echo "Startseite";
} elseif ( is_singular("blog") ) {
echo "Blog";
} elseif ( is_singular("project") ) {
echo "Projekt";
} elseif ( get_the_title() == "Datenschutz" ) {
echo "Datenschutz";
} elseif ( get_the_title() == "Impressum" ) {
echo "Impressum";
} elseif ( get_the_title() == "Contact" ) {
echo "Kontakt";
} elseif ( get_the_title() == "Blog" ) {
echo "Blog";
} elseif ( get_the_title() == "project" ) {
echo "Projekte";
}
Which almost works. The only Problem I am having is, when I'm on the Project and Blog page, where you can select a post. It doesn't show "Projekte" or "Blog".
When I'm clicking on a Project Post, it shows "Projekte". But when I'm on a Blog Post, it does not show "Blog".
Any ideas on how to fix that?
On mobile, I want to display what page my users are on. I have 6 top pages at the moment.
Home, Projects, Blog, Contact, Privacy Policy and Impressum. Both Projects and Blog have posts in them. Projects is a custom post type as well.
When a user clicks on Contact, title should change to contact. If they go to Project and click on a post, the title should say projects. I hope I make it clear.
I don't mind working with if
statements either if that's a solution.
Here is an image of what it would look like:
I hope I am making myself clear. Does anyone have a solution?
I have tried it with get_the_title()
to echo the title, but this does not give me proper results. When I'm on my Contact Page, it does say Contact. But once I'm on my home, project or blog page, it gives me the title of some post item, and not the title of the page as I want.
To give more context of what I want:
Imagine it like a breadcrumb, but instead, I only want one part of it. So instead of
Home > Contact
or
Home > Project > Some Post Title
I want only "Contact" or "Project". How would I go about that?
So now I have this code:
if ( is_front_page() ) {
echo "Startseite";
} elseif ( is_singular("blog") ) {
echo "Blog";
} elseif ( is_singular("project") ) {
echo "Projekt";
} elseif ( get_the_title() == "Datenschutz" ) {
echo "Datenschutz";
} elseif ( get_the_title() == "Impressum" ) {
echo "Impressum";
} elseif ( get_the_title() == "Contact" ) {
echo "Kontakt";
} elseif ( get_the_title() == "Blog" ) {
echo "Blog";
} elseif ( get_the_title() == "project" ) {
echo "Projekte";
}
Which almost works. The only Problem I am having is, when I'm on the Project and Blog page, where you can select a post. It doesn't show "Projekte" or "Blog".
When I'm clicking on a Project Post, it shows "Projekte". But when I'm on a Blog Post, it does not show "Blog".
Any ideas on how to fix that?
Share Improve this question edited Oct 16, 2020 at 18:50 Mähnenwolf asked Oct 15, 2020 at 8:47 MähnenwolfMähnenwolf 1479 bronze badges 3 |1 Answer
Reset to default 0After many attempts and help from others, I finally got a solution to my problem. That's the code I used:
<?php
if ( is_front_page() ) {
echo "Startseite";
} elseif ( is_singular("project") ) {
echo "Projekte";
} elseif ( get_the_title() == "Datenschutz" ) {
echo "Datenschutz";
} elseif ( get_the_title() == "Impressum" ) {
echo "Impressum";
} elseif ( get_the_title() == "Contact" ) {
echo "Kontakt";
} elseif ( get_post_type() == "project" ) {
echo "Projekte";
} elseif ( is_single() || is_home() ) {
echo "Blog";
}
?>
The only Problem I am having is, when I'm on the Project and Blog page, where you can select a post. It doesn't show "Projekte" or "Blog".
so what is the exactly unexpected page displayed? – RachC Commented Oct 17, 2020 at 1:44