Create a Reddit Style Website In Drupal
Sites that allow users to post and vote on content such as Reddit and Digg are hugely successful. In this tutorial we are going to create a Reddit style website in Drupal. What do I mean by “Reddit style website”?
- A user can post a link to an external URL.
- Users can upvote or downvote posted content.
- The content will appear displaying an automatically generated thumbnail from the external website.
- Users can filter results based on the content’s rating and when it was posted.
Below is a screenshot of what we will be creating.
Step 1: Configure ShrinkTheWeb
One of the nice things about Reddit is that is automatically creates a thumbnail of the website a user links to. This is helpful because it gives users a sneak peak at what they are about to visit.
Luckily, ShrinkTheWeb is a module that does just this.
- Create a free account at ShrinkTheWeb.
- After you register, go to the home tab and do the following:
-
Copy your Access Key and Secret Key
-
Add your domains to My Allowed Domains & IPs:
- Now that you have an account, install and enable the ShrinkTheWeb module.
- Navigate to admin/config/media/shrinktheweb
-
Add your Access Key and Secret Key from step 3
-
(Optional) Set the size of the Default Thumbnail size to xlg. This is the largest you can make the generated thumbnail with the free plan.
Step 2: Create a Link Content Type
Now that we configured ShrinkTheWeb, we can create a new custom content type. This will allow users to post links to external URLs.
- Before you create a new custom content type, install and enable the Link module.
- Create a new content type by going to admin/structure/types/add
-
Name your custom content type and adjust any configurations as you see fit.
-
Add a link field and make it required.
-
Under the teaser display admin/structure/types/manage/your-new-content-type/display/teaser set the Link label to Hidden and the format to [ShrinkTheWeb] Separate title and URL.
Step 3: Configure Rate Module
Now that we have the content type configured, we need to add the ability for users to rate content.
- Install and enable the Rate module
-
Navigate to admin/structure/rate/ and add a Number up / down widget.
-
On the next page, name your widget and configure the following settings:
-
Under NODE TYPES select the content type you created in Step 2
-
Under DISPLAY SETTINGS make sure Display in teaser is checked, and Appearance in teaser is set to Full widget.
-
Under INTERACTION set Which rating should be displayed? to Average rating. Set ** Which rating should be displayed when the user just voted?** to Average rating. Set S hould a second click on the same button delete the vote? to No.
-
Under PERMISSIONS set Roles to authenticated user and any other role you wish to grant this permission to. Check Allow author to rate his / her own content. Set Behaviour when user has no permission to vote to Redirect to login and show message.
Step 4: Configure The View
Now we have everything we need to create a view that will display our content and allow users to sort based in specific criteria.
- First, install and enable Views.
- Then, create a new view by going to admin/structure/views/add
-
Configure the view to show Content of the content type you created in Step 2: Create a Link Content Type sorted by unsorted. Create a page of teasers.
-
Under RELATIONSHIPS add a Content: Vote results relationship.
- Set the Value type to points
- Set the Vote tag to Normal Vote
- Set the Aggregation function to Average vote
-
Under FILTER CRITERIA add a Content: Post date field.
- Select Expose this filter to visitors, to allow them to change it
- Under Filter type to expose select ** Grouped filters**
- Under Widget type chose Select
- Add the following filters
- Today, Is greater than or equal to, An offset from the current time, - 24 hours
- This Week, Is greater than or equal to, An offset from the current time, - 7 days
- This Month, Is greater than or equal to, An offset from the current time, - 1 month
- This Year, Is greater than or equal to, An offset from the current time, - 1 year
- All Time, Is greater than or equal to, An offset from the current time, - 999 years
-
Under SORT CRITERIA add Vote results: Value
- Select Expose this sort to visitors, to allow them to change it
- Relationship Vote results
- Select Sort descending
- Check Treat missing votes as zeros
-
Under Under SORT CRITERIA add Content: Post date
- Select Expose this sort to visitors, to allow them to change it
- Select Sort descending
- Under Granularity select Second
- Save your view
You can then set the path of this view to be the homepage of your website at admin/config/system/site-information
Conclusion
This is just a bare bones example of how to create a Reddit style website. There’s obviously more to Reddit than just the above, but the ability for users to post and rate content is crucial. Adding the ShrinkToWeb functionality is a nice touch and adds an extra layer of detail. If you’re looking to use the features we created today more than once, you can always create an installation profile as outlined by Awang Setiawan.