how to use an argument to get a row to appear first in a View
Hello, I have a views slideshow, and in some cases I'd like a certain node to appear first in the order, I don't really care about the rest of the nodes just to move a certain node to be first in the slideshow. I'm looking to achieve this using an argument, maybe sending in the nid, or even better a certain value for another field. This is the use case - I have a slideshow of a certain product, where each row/node is a different color. I have a page with a bunch of these slideshows for different nodes. I'm looking for a way to have list page, display all the slideshows where the "Green" color nodes appear first, this is for a D7 site with drupal commerce - you can see it here: http://www.premiumbaby.co.il/koziol/drupal-7.0/%D7%9E%D7%95%D7%A6%D7%A8%D7%9 9%D7%9D Any pointers would be much appreciated. Idan
On Mon, Mar 28, 2011 at 9:03 AM, Idan Arbel <idan@arbel-designs.com> wrote:
Hello,
I have a views slideshow, and in some cases I’d like a certain node to appear first in the order, I don’t really care about the rest of the nodes just to move a certain node to be first in the slideshow.
I’m looking to achieve this using an argument, maybe sending in the nid, or even better a certain value for another field.
Hm. Well, if you've got no pager, here's an idea: You've got two displays - one display (the main one) which displays one item, and a second display that displays the rest. Display one is set up to display only the node provided via the argument, so that's automatically first. The second display is made into an attachment on the first display, which inherits the same argument, only on the second display the argument defines the node that isn't displayed. The tricky thing is the way you're displaying them as a grid - that may not work with having the page split into two views without a lot of work with css and/or alternate view templates. It might be simpler to have a 'grand' display of the argument node on top of a grid showing the rest of them. -- John Fiala www.jcfiala.net
Thanks for the tip, great idea but it's even trickier... I'm using a views slideshow to display those nodes together one at a time in a slideshow, so using two displays/views will be very difficult. Can I maybe use an argument to modify the node value from the views argument code? So I'll sort by a field - weight, by default all the nodes will have this field's value as 0, and I would sort according to the field. But if there's an argument I would modify field weight to 1 to all nodes that have that argument. Idan -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of John Fiala Sent: Monday, March 28, 2011 5:30 PM To: development@drupal.org Subject: Re: [development] how to use an argument to get a row to appear first in a View On Mon, Mar 28, 2011 at 9:03 AM, Idan Arbel <idan@arbel-designs.com> wrote:
Hello,
I have a views slideshow, and in some cases I'd like a certain node to appear first in the order, I don't really care about the rest of the nodes just to move a certain node to be first in the slideshow.
I'm looking to achieve this using an argument, maybe sending in the nid, or even better a certain value for another field.
Hm. Well, if you've got no pager, here's an idea: You've got two displays - one display (the main one) which displays one item, and a second display that displays the rest. Display one is set up to display only the node provided via the argument, so that's automatically first. The second display is made into an attachment on the first display, which inherits the same argument, only on the second display the argument defines the node that isn't displayed. The tricky thing is the way you're displaying them as a grid - that may not work with having the page split into two views without a lot of work with css and/or alternate view templates. It might be simpler to have a 'grand' display of the argument node on top of a grid showing the rest of them. -- John Fiala www.jcfiala.net
I had a similar requirement recently, and came up with what I thought was a pretty slick way to do it. My requirement was that a list of nodes needed a variable-sized list of "sticky" nodes that would float to the top of the list. The sticky list needed to be able to be manually sorted by content admins. Any slots in the view not filled by the sticky list could be filled with a "most recent" list of nodes. The answer is to use nodequeue to create the sticky list. In the admin options for node queue, there's an option to display the list in reverse, select that. When defining your view, define your first sort order as the nodequeue position descending. Set your second sort to be create date or whatever. The key is that any nodes not part of the nodequeue will have a position of NULL, and will naturally float to the bottom of the results. If the view is set to display 10 results, and the nodequeue is 6 items, then the remaining 4 items will be filled with the most recent nodes. If a content admin changes the nodequeue to be only 2 items, the remaining 8 will automatically fill in. This approach might be a bit overkill for what you're doing, but it will certainly work, and will give you some room to expand. HTH, Justin On Mon, Mar 28, 2011 at 10:30 AM, John Fiala <jcfiala@gmail.com> wrote:
On Mon, Mar 28, 2011 at 9:03 AM, Idan Arbel <idan@arbel-designs.com> wrote:
Hello,
I have a views slideshow, and in some cases I’d like a certain node to appear first in the order, I don’t really care about the rest of the nodes just to move a certain node to be first in the slideshow.
I’m looking to achieve this using an argument, maybe sending in the nid, or even better a certain value for another field.
Hm.
Well, if you've got no pager, here's an idea:
You've got two displays - one display (the main one) which displays one item, and a second display that displays the rest. Display one is set up to display only the node provided via the argument, so that's automatically first. The second display is made into an attachment on the first display, which inherits the same argument, only on the second display the argument defines the node that isn't displayed.
The tricky thing is the way you're displaying them as a grid - that may not work with having the page split into two views without a lot of work with css and/or alternate view templates. It might be simpler to have a 'grand' display of the argument node on top of a grid showing the rest of them.
-- John Fiala www.jcfiala.net
Thanks, But the question is how do I sort them using an argument? If you' look here: http://www.premiumbaby.co.il/koziol/drupal-7.0/%D7%9E%D7%95%D7%A6%D7%A8%D7%9 9%D7%9D you'll see grid of products, each item is actually a views slideshow of product entities of the different colors. What I'm looking to achieve is to load the view with an argument that would cause all the green products to be displayed first, or on a different page use a different argument and have all the orange products displayed first. Thanks for the idea though. Idan From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Justin Ellison Sent: Monday, March 28, 2011 5:44 PM To: development@drupal.org Subject: Re: [development] how to use an argument to get a row to appear first in a View I had a similar requirement recently, and came up with what I thought was a pretty slick way to do it. My requirement was that a list of nodes needed a variable-sized list of "sticky" nodes that would float to the top of the list. The sticky list needed to be able to be manually sorted by content admins. Any slots in the view not filled by the sticky list could be filled with a "most recent" list of nodes. The answer is to use nodequeue to create the sticky list. In the admin options for node queue, there's an option to display the list in reverse, select that. When defining your view, define your first sort order as the nodequeue position descending. Set your second sort to be create date or whatever. The key is that any nodes not part of the nodequeue will have a position of NULL, and will naturally float to the bottom of the results. If the view is set to display 10 results, and the nodequeue is 6 items, then the remaining 4 items will be filled with the most recent nodes. If a content admin changes the nodequeue to be only 2 items, the remaining 8 will automatically fill in. This approach might be a bit overkill for what you're doing, but it will certainly work, and will give you some room to expand. HTH, Justin On Mon, Mar 28, 2011 at 10:30 AM, John Fiala <jcfiala@gmail.com> wrote: On Mon, Mar 28, 2011 at 9:03 AM, Idan Arbel <idan@arbel-designs.com> wrote:
Hello,
I have a views slideshow, and in some cases I'd like a certain node to appear first in the order, I don't really care about the rest of the nodes just to move a certain node to be first in the slideshow.
I'm looking to achieve this using an argument, maybe sending in the nid, or even better a certain value for another field.
Hm. Well, if you've got no pager, here's an idea: You've got two displays - one display (the main one) which displays one item, and a second display that displays the rest. Display one is set up to display only the node provided via the argument, so that's automatically first. The second display is made into an attachment on the first display, which inherits the same argument, only on the second display the argument defines the node that isn't displayed. The tricky thing is the way you're displaying them as a grid - that may not work with having the page split into two views without a lot of work with css and/or alternate view templates. It might be simpler to have a 'grand' display of the argument node on top of a grid showing the rest of them. -- John Fiala www.jcfiala.net
On 3/28/2011 9:00 AM, Idan Arbel wrote:
Thanks,
But the question is how do I sort them using an argument?
If you’ look here:
Set your argument to Global: Null so that the argument does not affect the view itself. Utilize hook_views_pre_render() and use array manipulation to reorder $view->result before anything is rendered.
participants (4)
-
Earl Miles -
Idan Arbel -
John Fiala -
Justin Ellison