Active Class on Blog-Menu and Blog-Posts URL
Hello,
i am working on my own Theme with this Navigation:
<?php foreach ($staticContent as $staticPage): ?>
<?php $active = ($staticPage->key() == $url->slug())? 'active': ''; ?>
<a class="<?php echo $active; ?>" href="<?php echo $staticPage->permalink(); ?>"><?php echo $staticPage->title(); ?></a>
<?php endforeach ?>
In my backend i set the static page "home" as my homepage and "/blog/" as my Blog-Page (Setting: URL-Filter).
When i Click "Blog" on my Navbar, the "active"-class is not showing up.
i guess it is because the slug() has a problem with the "/" at the end of the url "domain.com/blog/" is this correct? Is There a way to fix this?
Also i am confused with how my blog-posts show up in the URL.
I thought a Blogpost should have the URL "domain.com/blog/post-name" but instead it is "domain.com/postname" - is there a way to change it?
Thanks in advanced.
i am working on my own Theme with this Navigation:
<?php foreach ($staticContent as $staticPage): ?>
<?php $active = ($staticPage->key() == $url->slug())? 'active': ''; ?>
<a class="<?php echo $active; ?>" href="<?php echo $staticPage->permalink(); ?>"><?php echo $staticPage->title(); ?></a>
<?php endforeach ?>
In my backend i set the static page "home" as my homepage and "/blog/" as my Blog-Page (Setting: URL-Filter).
When i Click "Blog" on my Navbar, the "active"-class is not showing up.
i guess it is because the slug() has a problem with the "/" at the end of the url "domain.com/blog/" is this correct? Is There a way to fix this?
Also i am confused with how my blog-posts show up in the URL.
I thought a Blogpost should have the URL "domain.com/blog/post-name" but instead it is "domain.com/postname" - is there a way to change it?
Thanks in advanced.
- Edi
- Site Admin
- Posts: 3121
- Joined: Sun Aug 09, 2015 5:01 pm
- Location: Zurich
- Has thanked: 54 times
- Been thanked: 77 times
- Contact:
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
i made the changes in the functions.php:
but it doesnt changed anything for me with the "active" class "problem".
maybe i misunderstood something?
i didn't had a problem to set the blog loop on a different page than home, that was possible without the changes above.
but thanks for the fast and helpful answers edi
Code: Select all
if (empty($args['homepage'])) {
$args['homepage'] = '';
$args['uriBlog'] = '';
}
if (empty($args['pageNotFound'])) {
$args['pageNotFound'] = '';
}
if (isset($args['uriPage'])) {
$args['uriPage'] = Text::addSlashes($args['uriPage']);
}
if (isset($args['uriTag'])) {
$args['uriTag'] = Text::addSlashes($args['uriTag']);
}
if (isset($args['uriCategory'])) {
$args['uriCategory'] = Text::addSlashes($args['uriCategory']);
}
if (!empty($args['uriBlog'])) {
$args['uriBlog'] = Text::addSlashes($args['uriBlog']);
} else {
if (!empty($args['homepage']) && empty($args['uriBlog'])) {
$args['uriBlog'] = '/blog/';
} else {
$args['uriBlog'] = '';
}
}
maybe i misunderstood something?
i didn't had a problem to set the blog loop on a different page than home, that was possible without the changes above.
but thanks for the fast and helpful answers edi
nope, i just started with this version 2 days ago.
do you maybe have a solution tipp for my firstquestion:
my navigation in my template:
<?php foreach ($staticContent as $staticPage): ?>
<?php $active = ($staticPage->key() == $url->slug())? 'active': ''; ?>
<a class="<?php echo $active; ?>" href="<?php echo $staticPage->permalink(); ?>"><?php echo $staticPage->title(); ?></a>
<?php endforeach ?>
When i Click "Blog" on my Navbar, the "active"-class is not showing up.
i guess it is because the slug() has a problem with the "/" at the end of the url "domain.com/blog/" is this correct? Is There a way to fix this?
do you maybe have a solution tipp for my firstquestion:
my navigation in my template:
<?php foreach ($staticContent as $staticPage): ?>
<?php $active = ($staticPage->key() == $url->slug())? 'active': ''; ?>
<a class="<?php echo $active; ?>" href="<?php echo $staticPage->permalink(); ?>"><?php echo $staticPage->title(); ?></a>
<?php endforeach ?>
When i Click "Blog" on my Navbar, the "active"-class is not showing up.
i guess it is because the slug() has a problem with the "/" at the end of the url "domain.com/blog/" is this correct? Is There a way to fix this?