Jump to content

PageArray problem


vxda
 Share

Recommended Posts

Hi my problem is a bit complicated, first the data structure.
 

NEWS

     Category 1

          News 1

          News 2

          ...

     Category 2

          News 1

          News 2

          ...
and so on.

My news template can be shown in 2 ways

*as a news : checkbox text_yes=0

*as important news:checkbox text_yes=1

On home page im showing all news from all categories also im showing important news(text_yes=1) on every 7th item.
Im grabbing pages like this :

$news= $pages->find('has_parent=1020, template=news, sort=-created, text_yes=0, limit=25');

Then im creating array to populate it with every 7th news item

 

$afterArr = array();
	foreach ($news as $item) {
		if ($count % 7 == 0) {
			array_push($afterArr, $item);
		}
		$count++;
	}

Now im looking for all news from all categories that are text_yes=1

$allText = $pages->find("template=news, text_yes=1, sort=-created");

Now im updating my pageArray with important news

$i = 0;
foreach ($allText as $textPage) {
	if ($i < count($afterArr)) {
		$news= $news->insertAfter($pages->get($textPage->id), $pages->get((string)$afterArr[$i]));
		$i++;
	}

And now im getting confused cause my pagination dont work properly
normal news are pagin good but my important news are repeating on each page.

so what i was trying to do is to get my pagesArray into array and then into string:
 

First of all i changed limit of grabed news to null

$news= $pages->find('has_parent=1020, template=news, sort=-created, text_yes=0');

then

$pagesArr = $news->getArray();
	$p = implode('|', $pagesArr);

and then use it like this :
 

$news= $pages->find('id='.$p .',template=news, limit=25');

first page is wroking, second page shows all news on one page.

my foreach looks like this :

foreach ($news $item) {
     if ($item->text_yes == "1") {
        $out .="important news";
     }
     if ($item->text_yes == "0"){
          $out .="news";
     }
}

im a beginner php so have a fealing like im overdoing something here.
Would be grateful for help in this.

i hope i explained all clearly ;)

Cheers

Pawel
 

Link to comment
Share on other sites

I think im getting closer to solution.
Im creating new page array and i put all pages in the order i want them to be displayed
 

$pa = new PageArray();
	$pa->import($news);

thing is that when im doing this to limit them per page, it automaticly gets reordered. Is there a way to prevent it from getting reorded ?

$pa = $pages->find(template=news, limit=25);
Link to comment
Share on other sites

Sorry, in a bit of a rush, so not reading through your post well enough, but is it as simple as:

$ordered = $pa->find("template=news, limit=25");

Sounds like you don't want to be finding from the full $pages array anymore, but rather your ordered $pa array?

  • Like 1
Link to comment
Share on other sites

Thx Adrian for your replay, it looks like its working but ... i got same news on every page something wrong with pagination now ;/

i got url/page2 and so one but got same news list on every page


 

Edited by vxda
Link to comment
Share on other sites

here is my code:

$allText = $pages->find("template=news, text_yes=1, sort=-created");   // Here im grabbing all special news

if ($page->id === 1) {  // If in home page 
	$news= $pages->find('has_parent=1020, template=news, sort=-created, text_yes=0'); // Here im grabbing all normal news withour specials
	$count=1;
	$afterArr = array();
	foreach ($news as $item) {   // Here im lookin for page id of every 6th news for later.
		if ($count % 6 == 0) {
			array_push($afterArr, $item);
		}
		$count++;
	}

	$i = 0;
	foreach ($allText as $textPage) {
		if ($i < count($afterArr)) {
			$news = $news->insertAfter($pages->get($textPage->id), $pages->get((string)$afterArr[$i])); // Here im inserting special news pages on every 6th normal news item.
			$i++;
		}
	}
	$news = $news->find('template=news, limit=25'); // here im setting item limit for each page
}else {
	$pa = $page->children('template=news, sort=-sort, limit=25'); // here will be option when not in homepage
}

foreach ($news as $newsItem ) {
if ($newsItem ->text_yes == "1") {
$out .= SPECIAL NEWS
}
if ($newsItem ->text_yes == "0") {
NORMAL NEWS
}
}


$pagination = '';

$pagination .="<nav class='pagination'>";
		$pagination .= $news->renderPager();
	$pagination .="</nav>";
Link to comment
Share on other sites

hmm i was trying to cheat that pager a bit and  i did something like this:

detecting what page im on with:
 

$input->pageNum

and then acording to that im setting offset of my pageArray

$offset = 0;
	if ($input->pageNum > 1) {
		$offset = $input->pageNum * 25 - 25;
	}

and it started sorting news properly, but now the pagination links are down, after i go after /page2 it thinks his still on /page2 next page link shows allways /page2

$news= $news->find("start=".$offset.", limit=25");

Strange thing is that $input->pageNum show correctly on wich page i am.

so there has to be something wrong with renderPager

$pagination .= $news->renderPager();
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...