Hey folks,
i just created a site with the pagination function. It works perfectly at all.
So now i want to create a sidebar within the years of the blog posts.
2015
2014
2013
…
for jumping direct to the article i use the “section” function. That works perfectly, but i have implemented paginate(10) so that only 10 blog posts appear on the actually site.
So my problem is when i click for example on year 2011 in the sidebar and the article is on the next page he didnt’t check that because he didn’t find the right section. Is there any solution or anyone could help me?
sorry for my english
Thanks
Flo
I don’t understand what you mean by “section function”. Could you post your code, pls.?
This is my sidebar:
<ul class="nav list-group" id="sidebar">
<li class="list-group-item"><a href="#2015">2015</a></li>
<li class="list-group-item"><a href="#2014">2014</a></li>
<li class="list-group-item"><a href="#2013">2013</a></li>
</ul>
And this is my content:
<section id="<?php echo $article->date('Y'); ?>">
<div class="row clearfix">
<div class="col-md-3 column">
<?php if($image = $article->images()->sortBy('sort', 'asc')->first()): ?>
<a class="thumbnail" rel="gallery" href="<?php echo $article->url() ?>">
<?php echo thumb($image, array('width' => 300, 'height' => 200, 'crop' => true)) ?>
</a>
<?php endif ?>
</div>
<div class="col-md-9 column">
<a href="<?php echo $article->url() ?>"><h4 class="media-heading"><?php echo html($article->title()) ?></h4></a>
<p><?php echo excerpt($article->text(), 400) ?></p>
<p><a class ="btn btn-success" href="<?php echo $article->url() ?>">Weiterlesen</a></p>
<p class="pull-left"><?php echo $article->date('F dS, Y'); ?></p>
<p class="pull-right">
<?php foreach(str::split($article->tags()) as $tag): ?>
<span class="label label-default"><?php echo $tag; ?></span>
<?php endforeach ?>
</p>
</div>
</div>
</section>
One thing is that using an ID that starts with a number is not valid html, but I need to have a closer look at your code later.
Somehow this doesn’t make sense to me, if I get this right, then you have a new section for each article, but these sections can be on different pages, because they are paginated?
But if so, you will certainly have several articles with an ID of the same year, which would be incorrect, because you can only use an ID once on a page.
Or do you filter the articles by date first and then have all the articles that belong to a year within that section? Where is your foreach-loop?
Yes the newest one appears on the top of the site. And for that i have a foreach loop.
I think you need to post your complete code, with logic and everything, otherwise I don’t get it
<div class="col-md-3 column" id="leftCol">
<ul class="nav list-group" id="sidebar">
<li class="list-group-item"><a href="#2015">2015</a></li>
<li class="list-group-item"><a href="#2014">2014</a></li>
<li class="list-group-item"><a href="#2013">2013</a></li>
<li class="list-group-item"><a href="#2012">2012</a></li>
<li class="list-group-item"><a href="#2011">2011</a></li>
<li class="list-group-item"><a href="#2010">2010</a></li>
<li class="list-group-item"><a href="#2009">2009</a></li>
<li class="list-group-item"><a href="#2008">2008</a></li>
</ul>
</div><!-- /col-md-3 Navigation links-->
<div class="col-md-9 column">
<?php $articles = $pages->find('neuigkeiten')->children()->visible()->flip()->paginate(10) ?>
<?php foreach($articles as $article): ?>
<?php if($article->template() == 'neuigkeiten.normal'):?>
<section id="<?php echo $article->date('Y'); ?>">
<div class="row clearfix">
<div class="col-md-3 column">
<?php if($image = $article->images()->sortBy('sort', 'asc')->first()): ?>
<a class="thumbnail" rel="gallery" href="<?php echo $article->url() ?>">
<?php echo thumb($image, array('width' => 300, 'height' => 200, 'crop' => true)) ?>
</a>
<?php endif ?>
</div>
<div class="col-md-9 column">
<a href="<?php echo $article->url() ?>"><h4 class="media-heading"><?php echo html($article->title()) ?></h4></a>
<p><?php echo excerpt($article->text(), 400) ?></p>
<p><a class ="btn btn-success" href="<?php echo $article->url() ?>">Weiterlesen</a></p>
<p class="pull-left"><?php echo $article->date('F dS, Y'); ?></p>
<p class="pull-right">
<?php foreach(str::split($article->tags()) as $tag): ?>
<span class="label label-default"><?php echo $tag; ?></span>
<?php endforeach ?>
</p>
</div>
</div>
</section>
<hr />
<?php endif ?>
<?php endforeach ?>
</div><!-- /.col-md-9 Neuigkeiten Auflistung-->
Here it is
What this code is doing is create a new section for every article within the foreach-loop. So let’s suppose you have five articles in 2015, four in 2014, six in 2013 etc. you will have 5 sections with the ID 2015, four with the ID 2014, and six with the ID 2013, which is not valid html and does not make sense, either. Because your link will always jump to the first anker it encounters.
What I would expect when I click on a link that contains a year, is that all articles are filtered by that year and the page will show a list of all articles written in 20xx, and not to jump to a particular article from year x (which one?).
So if you want to filter the articles by year, you would use a href with a parameter in your sidebar link, that would filter your articles by year.
Thanks first @texnixe for your time
I think thats sounds definitely better then my solution. So if i use the parameter in the href tag a new site is loading and all articles of for e.g. year 2015 will appear on this site?
I’m not good in programming, but kirby does it a little bit easier for me Sorry