Thanks for the help, and this is the result. Any way to make it better?
<?php
include("./head.inc");
/**
* News template, the base part!
*
* By Max Allan Niklasson
*/
$tagQuery = $sanitizer->text($input->get->tag);
$label = array(
'altTag' => 'Bild',
'postedUnder' => 'Postad under',
'readMore' => 'Läs mer »»',
'published' => 'Publicerad den',
'by' => 'av',
'prev' => 'Föregående',
'next' => 'Nästa',
'tagExpl' => 'Filtrering av nyheter med taggen: <em>'.$tagQuery.'</em>, visar %s träff(ar) av %s träff(ar). <br/> <a href="'.$page->url().'">Visa alla nyheter</a>'
);
/**
Here I have one issue
when set $limit = 1, the pager don't work...
Solution?
**/
$limit = 3;
//To fix the pager
$start = ($sanitizer->text($input->get->page) ? $limit * $sanitizer->text($input->get->page) - $limit : 0);
function thumbGet(Page $page, $label =null){
if($page->images){
$image = $page->images->first();
if($image){
if($image->width() > 250){
$thumb = $image->size(250);
}elseif($image->height() > 250){
$thumb = $image->size(0, 250);
}else{
$thumb = $image;
}
$return =
"\n\t\t\t\t\t\t\t\t".
'<div class="news-image">'.
"\n\t\t\t\t\t\t\t\t\t".
'<img src="'.$thumb->url().'" alt="'.$label[altTag].'" />'.
"\n\t\t\t\t\t\t\t\t\t".
'<p>'.$image->get('description').'</p>'.
"\n\t\t\t\t\t\t\t\t".
'</div>';
return $return;
}else{return false;}
}
else{
return false;
}
}
function processNewsItem(Page $news, Users $users, $label){
$writer = $news->createdUser;
$tags = split(',',$news->news_tags);
echo "\n\t\t\t\t\t".'<div class="news-item">';
echo "\n\t\t\t\t\t\t".'<h2>'.$news->title.'</h2>';
echo "\n\t\t\t\t\t\t\t".'<p>';
echo "\n\t\t\t\t\t\t\t\t".'<div class="news-summary">'.$news->summary.'</div>';
if(thumbGet($news)){
echo thumbGet($news, $label);
}
echo "\n\t\t\t\t\t\t\t".'</p>';
if($tags[0]){
echo "\n\t\t\t\t\t\t\t".
"<div class='news-info'>";
echo $label[postedUnder].": ";
$tagCount = 0;
foreach($tags as $tag){
if($tagCount != 0) {echo ' | ';}
echo "\n\t\t\t\t\t\t\t\t".
'<a href="?tag='.$tag.'">'.$tag.'</a>';
$tagCount++;
}
echo "\n\t\t\t\t\t\t\t\t".
'<div class="news-published">'.$label[published].': '.date("Y-m-d \k\l\. H:i:s", $news->created).' '. $label[by] .' '.$writer->name.'</div>';
echo "\n\t\t\t\t\t\t\t".
'</div>';
}
echo "\n\t\t\t\t\t\t\t".'<div class="news-read-more">'.
"\n\t\t\t\t\t\t\t\t".'<a href="'.$news->url.'">'.$label[readMore].'</a>'.
"\n\t\t\t\t\t\t\t".'</div>';
echo "\n\n\t\t\t\t\t".'</div> <!-- news-item -->';
}
function pagination(PageArray $cPages, PageArray $tPages, $limit, $label){
//The URL fix
$input = wire("input")->get;
$sanitizer = wire("sanitizer");
$URL = ($sanitizer->text($input->tag) ? '?tag='.$sanitizer->text($input->tag).'&page=#NR#' : '?page=#NR#');
//The Totally number of pages
$tot = $tPages->count();
$pages = round(($tot / $limit) + 1);
if($tot <= $limit){
}else{
echo '<ul class="news-pager">';
if($pages <= $sanitizer->text($input->page) && 0 < ($sanitizer->text($input->page) -1) ){
echo '<li><a href="'.str_replace('#NR#', ($sanitizer->text($input->page)-1), $URL).'">'.$label[prev].'</a>';
}
for($i = 1; $i <= $pages; $i++){
$class = '';
if($sanitizer->text($input->page) == $i){
$class = 'class="active"';
}elseif($sanitizer->text($input->page) == 0 && $i == 1){
$class = 'class="active"';
}
echo '<li '. $class .'><a href="'.str_replace('#NR#', $i, $URL).'">'.$i.'</a>';
}
if($pages >= $sanitizer->text($input->page) && $pages >= ($sanitizer->text($input->page) +1) ){
echo '<li><a href="'.str_replace('#NR#', ($sanitizer->text($input->page)+1), $URL).'">'.$label["next"].'</a>';
}
echo '</ul>';
}
}
###### Let's Print it out! #######
/**
The viewer from tag query
**/
if($tagQuery){
$counter = $page->children('template=news.article, news_tags*='.$tagQuery.', sort=-date, sort=-id ');
$newsItems = $page->children('template=news.article, news_tags*='.$tagQuery.', sort=-date, sort=-id, start='.$start.', limit='.$limit);
if($newsItems->count()) {
printf($label->tagExpl, $newsItems->count(), $counter->count() );
echo "\t\t\t\t".'<div class="news-list">';
foreach($newsItems as $news){
processNewsItem($news, $users, $label);
}
echo "\n\n\t\t\t\t".'</div><!-- news-list -->';
}
}else{
/**
The Normal News viewer
**/
$counter = $page->children('template=news.article');
$newsItems = $page->children('template=news.article, sort=-date, sort=-id, start='.$start.', limit='.$limit);
if($newsItems->count()) {
echo "\t\t\t\t".'<div class="news-list">';
foreach($newsItems as $news){
processNewsItem($news, $users, $label);
}
echo "\n\n\t\t\t\t".'</div><!-- news-list -->';
}
}
pagination($newsItems, $counter, $limit, $label);
include("./foot.inc");





Find content
Male
