I've created a view using two content types:

1) "testimonials_with_pictures"
and:
2) "testimonials_without_pictures"

... in a view named "testimonials" (at the alias: "/Success-Stories").

Since I only have 5 testimonials with pictures, I put them in a "page" display and have them shown at the top of the view, followed by the others, shown in a "block" display beneath. The block display uses a pager.

Each display is formatted differently and uses different fields, sorting and styling.

You can see the view here.

It works great, except when using the pager to move to page 2 ("/Success-Stories?page=1"), then the "page display" prints at the top again, followed by the rest of my testimonials without pictures (the "block display"). Same on subsequent pages, of course.
8^/

My first instinct is to choose which display types to show based on the URL; i.e.: if there's a query string in the url: "?page=" then don't print the "page" display type, just print the "block."

So I came up with what I thought was a simple enough solution:

<?php

/* Don't print the "Page" display if we're NOT on page one of the view */

   $showpage = getenv("REQUEST_URI"); 
          if(strpos($showpage, "?page=")) {

          /* THEN DO WHAT???  */

    exit;
}
*/?>

I thought I'd drop it into "views-view-testimonials.tpl.php" following the "if(strpos($showpage, "?page=")) {" statement with something like...

$view->set_display('block')

... but I don't know what the correct syntax would be, since I only started playing with Drupal two months ago. I'm not even sure if the template approach makes sense.
:-(

Thanks for any Help

Comments

merlinofchaos’s picture

It works great, except when using the pager to move to page 2 ("/Success-Stories?page=1"), then the "page display" prints at the top again, followed by the rest of my testimonials without pictures (the "block display"). Same on subsequent pages, of course.

How do you want the block to behave when the main page is paged?

(Also you might consider using an attachment rather than a block, but that is up to you).

boblangdon’s picture

Thank you so much for the fast response! I'll need to investigate "attachment" displays.

How do you want the block to behave when the main page is paged?

I want it to show (on all pages).

Actually, I may have been too quick to give up on this. I'm almost figured this out...

I deleted the "page display" and made a second "block display" to replace it, then enabled it in the block configuration page using php to show the block display (previously the page display) only if on the view page/alias AND only if on page 1 of the results:

<?php
$showpage = getenv("REQUEST_URI"); 
return ((strpos($showpage, "Success-Stories")) && (!strpos($showpage, "page=")));
?>

It works as expected: I see both blocks on the initial view, and only results from the second block on subsequent pages (clicking "next" in pager).

BUT... now I get a message at the top of the view: "The requested page could not be found."
And my entire left-sidebar region went away (on that page only).
And the urls now have "&destination=Success-Stories" appended to them.

Doh!!!

Is this something in Views I messed up or something in Drupal I messed up.?

The page can be seen HERE

merlinofchaos’s picture

Recommendation: The view that is paged? Make that the 'page' display. The view that is *not* paged, make that an 'attachment' display that is set to 'show above'. I think the lack of a 'page' display is causing the current problems because Views doesn't actually know what URL to go to.

boblangdon’s picture

Aha!
Thank you, merlinofchaos, for restoring order to my virtual kingdom.
;^)

boblangdon’s picture

Regarding attachments....

Is there a way, within Views, to tell the attachment display to only show itself on page 1 of the results (when using a pager within the view)?

thx

merlinofchaos’s picture

Status: Active » Fixed

Hmm. I would add the global: null argument (only to the attachment; be sure to override arguments for the attachment). Set the null argument to have PHP code validation, and use a bit of php to check $_GET['page'] and make sure it is empty().

boblangdon’s picture

Sorry to bother you again merlinofchaos,

I did as you said and added the code:

$ispageone=$_GET['page'];
return $ispageone;

Which should return false if on page 1 and true if on subsequent pages, yes?
But when I visit the view, I get "page cannot be found"

I also tried:

$showattachment = getenv("REQUEST_URI");
return (strpos($showattachment, "page=")));

and

if (empty($_GET['page'])) {
return true;
}

Which resulted the same.

In the argument form, I left the title and breadcrumb fields empty.
I checked "Action to take if argument is not present: Provide default argument"
"Default argument type:PHP Code"
"Validator: PHP Code"
"Fail basic validation if any argument is given: tried checked and unchecked"

I notice there's a text field with no label above the textarea where I entered the php.
Do I need to enter something in this field?

I'm sure I'm missing something obvious here.

boblangdon’s picture

Ooops.
My bad, I had a typo in my page display path.
Now, no more "page not found."

But my php isn't delivering the desired results either.
8-(

The attachment still appears on all results pages.

boblangdon’s picture

I found one solution was to add this directly to my "views-view.tpl.php" template:

<?php
if (($attachment_before) && (empty($_GET['page']))): ?>
    <div class="attachment attachment-before">
      <?php print $attachment_before; ?>
    </div>
  <?php endif; ?>

Thank You

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.