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
Comment #1
merlinofchaos commentedHow 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).
Comment #2
boblangdon commentedThank you so much for the fast response! I'll need to investigate "attachment" displays.
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:
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
Comment #3
merlinofchaos commentedRecommendation: 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.
Comment #4
boblangdon commentedAha!
Thank you, merlinofchaos, for restoring order to my virtual kingdom.
;^)
Comment #5
boblangdon commentedRegarding 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
Comment #6
merlinofchaos commentedHmm. 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().
Comment #7
boblangdon commentedSorry to bother you again merlinofchaos,
I did as you said and added the code:
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:
and
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.
Comment #8
boblangdon commentedOoops.
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.
Comment #9
boblangdon commentedI found one solution was to add this directly to my "views-view.tpl.php" template:
Thank You