Jump to content

Pagination Interfering with Function output


creativejay
 Share

Recommended Posts

This page is exhibiting issues with the output of my right column sidebar, which is built in a function. It appears fine on the initial page, but when clicking to the additional pages, anything output by the functions eventsListSidebar and docListSidebar disappears.

http://www.spectra254.com/about-us-test/news-test/

Hoping someone could lend me their eyes and point out what might be the culprit.

Function code (254_functions.inc):

function eventsListSidebar(){
 
	$events = wire("pages")->find("parent=/about-us/events/,template=254_events,include=hidden,limit=3,sort=event_startDate");
 
	$out .="<ul>";
		
	//Loop through the pages
 
	foreach($events as $event){
		$startMonth = date(n, $event->event_startDate);
		$endMonth = date(n, $event->event_endDate);
		
		if ($endMonth > $startMonth) { 
			$startDateFormatted = date('j M', $event->event_startDate);
			$endDateFormatted = date('j M', $event->event_endDate);
		} else {
			$startDateFormatted = date('j', $event->event_startDate);
			$endDateFormatted = date('j M', $event->event_endDate);
		}
		$out .="<li><h3 class='sub_header_2'>{$startDateFormatted} – {$endDateFormatted}</h3>";
		$out .="<p>{$event->title}<br />";
		if($event->event_city){
			$out .="{$event->event_city} <br />";
		} else { $out .="";}
		if ($event->event_booth){
			$out .="{$event->event_booth}";
		} else { $out .="";}
		$out .="</p></li>";
 
	}
	$out .= "</ul>";
	echo $out;
 
}

function docsListSidebar(){
 
	$docs = wire("pages")->find("parent=/product-literature/,template=document,limit=5,sort=sort");
 
	$out .="<ul>";
		
	//Loop through the pages
 
	foreach($docs as $doc){
		$out .="<li><div><a href='{$doc->Link}' target='_blank'><img src='";
		$out .=wire("config")->urls->assets; 
		$out .="images/documenticon.png' alt='{$doc->title}' class='floatleft' /><span style='display: block;height: 15px; padding-top:5px;'>{$doc->title}</span></a></div></li>";
	}
	$out .= "</ul>";
	echo $out;
 
}

output for /news-test/ called as newsList() within that same 254_functions.inc file:

function newsList(){
 
	// Grab the page name from the url
 
	$thisCategory = wire("page")->name;
 
	// If the category is not called "news" then output the category name as a selector for the find.
 
	if($thisCategory !="news") {
		$category = "article_category.name=" . $thisCategory;
	}	
 
	// Get the news posts - limited to ten for later pagination
 
	$newsposts = wire("pages")->find("template=254_news_article,limit=5,sort=-published_date");
 
	$out =" ";
 
	//Loop through the pages
	$out .="<div class='pagination'>";
	$out .= $newsposts->renderPager(array(
 
				    'nextItemLabel' => "Next",
				    'previousItemLabel' => "Prev",
				    'listMarkup' => "<div class='pagination'>{out}</div>",
				    'itemMarkup' => "<span class='pagelink'>{out}</span>",
				    'linkMarkup' => "<a href='{url}'>{out}</a>"   
 
					));
	$out .="</div>";

	foreach($newsposts as $child) {
		$target = $child->get("Link|url");
		$out .= "<div class='simple-row'>";
		
		if($child->prod_image) {
			$img = $child->prod_image;
								
			if($img->width > $img->height) {              // check for orientation
				$thumb = $img->width(150);  // we have a landscape oriented image
			 } else {
				$thumb = $img->height(150);     // we have a portrait oriented image
			 }
		
			$out .= "<span style='display: block; width: 150px; height: 150px;float: left; margin-right: 25px;'><a href='{$target}'><img src='{$thumb->url}' class='floatleft' alt='{$child->get("title")}'></a></span>";
			}
			
		$out .="
		<div class='text-float'>
		<h2 class='bold_sub_title'><a href='{$target}'>{$child->get("headline|title")}</a></h2>";
		$out .= "<div class='text_block'><p>";
		$content = $child->body;
		$out .= limit_words($content,30);
		$out .= "... <a href='{$target}'>Read More</a></p></div>
		</div>
		</div>";
}

	// Pagination
 
	$out .="<div class='pagination'>";
	$out .= $newsposts->renderPager(array(
 
				    'nextItemLabel' => "Next",
				    'previousItemLabel' => "Prev",
				    'listMarkup' => "<div class='pagination'>{out}</div>",
				    'itemMarkup' => "<span class='pagelink'>{out}</span>",
				    'linkMarkup' => "<a href='{url}'>{out}</a>"   
 
					));
	$out .="</div><div style='display:block; width: 100%; height: 35px;'></div>";
 
	echo $out;
 
}

the sidebar itself renders in 254_foot.inc (this is just the segment pertaining to the above)

if($page->template == "254_news") {
		echo "<div class='col span_1_of_4'>
			<div class='about_side_bar'>
				<h2>Product Literature</h2>";
				docsListSidebar();
				echo "<div style='display: block; height: 1em; width: 100%;'></div>";
				echo "<h2>Tradeshow Schedule</h2>";
				echo "<br ><a href='{$pages->get(1024)->url}'>View the Full Schedule</a>";
				eventsListSidebar();
				echo "
			</div>
		</div>";
		}

Thanks in advance!

Link to comment
Share on other sites

I think this will fix it:

$newsposts = wire("pages")->find("template=254_news_article,limit=5,sort=-published_date,start=0");

Note the addition of start=0 - this is to override the insertion of start from the pagination code.

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...