Need some help with your project? Contact me

How to create a Promo block using Nodequeue and Views

Happy New Year everyone!

In this tutorial I am going to show you how you can use Nodequeue to create yourself an awesome Promo content block. If you follow along, by the end of this tutorial you will have a block on the front page listing content that you easily select and sort based on the requirements of the moment. So lets go ahead and see how.

For this tutorial, my content will consist of 4 images from Article nodes that I want to promote to my Promo block whenever and in whichever position I want. So lets begin.

First, we'll need a simple View that displays our content. Here you can use whatever type of content you need and style its output however it best fits your design. I'm going with a View listing 4 nodes using fields instead of content and showing only the image field. I remove everything that is in the sorting section and for filtering I make sure only published nodes of the type Article show up. Save the View and you can already position it wherever you want on the homepage to see the 4 images. No biggie.

But currently, the sorting and filtering is quite unfriendly for something such as a Promo block where you need to be able to quickly change which nodes go there and in what order. And yes you could add a field to the content type and promote it to the Promo block if you need. But for sorting? You'll probably end up editing the authoring date all the time to make sure the sorting is in the way you want at any given moment. So lets use Nodequeue instead.

After installing it (drush dl nodequeue && drush en nodequeue -y), go to Structure->Nodequeues->Add a simple queue. Give it a title and the number of nodes you'd like this queue to max out with. In my case it will be 4. Then select the content type you are allowed to add to it and save. Now let's go back to edit our View to make sure it displays only content that is in this particular nodequeue we just created.

First up, add a relationship of the type Nodequeue: Queue and go ahead and limit it to the queue you just created. Now we have access to the nodequeue information in our View. So add a new filter of the type Nodequeue: In queue using this relationship. Set that to true to make sure only nodes present in this queue are listed by the View.

Now add a sorting criterion of the type Nodequeue: Position and don't mind whether it is ascending or descending. The position will be given by the drag'n'drop functionality of Nodequeue with which you will control manually the position of the nodes.

OK, now that you have your View you can go check it out on the home page and you'll notice there is nothing in it anymore. Well you have to add some nodes to the queue you created earlier. And this is the part where your life becomes easier. Now whenever you need stuff in the promo block, you'll just go to the queue and add the node in it. And you can easily adjust the position in which they appear with the drag'n'drop. Cool no?

Hope this helps

Comments

Another nice example of relationships in Views.
Many ways this can be put into use, too!
Thank you for sharing.

thank you for sharing this article through. Knowledge of drupal feels very cumbersome to read, but this post changed everything because I can easily understand. I'm still learning to make blog and the content of the blog is much better than mine. This blog gives me a lot of inspiration.

Add new comment

You must have Javascript enabled to use this form.