Random Node or Front page in Drupal like Stumbleupon

What I really wanted was that every day my website should be updated with some random previous content, that way the visitors see new content if they visit everyday.

There are couple of methods to do this. First you can create a block and display it in homepage with 1 node in it. You can name it as spotlight or something, or you can create your entire front page with random content. In this method the content will be randomized upon refresh it wont be updated daily. Lets look at the first method.

Method 1: Basically you have to create a view with “Sort Order” as Random. This way if its a block or page it will show new content upon refresh. Details are at http://drupal.org/node/161292 . You can create an attractive button to invite your users to click , everytime they click it will be refreshed with new content.

A) Create a New View

4.7.x Home >> Administer >> views : Add
( /admin/views/add )

5.x Home >> Administer >> Site building >> Views: Add
( /admin/build/views/add )

B) Basic Information Block

  • Add “Name:” and “Description:”
  • UnCheck all boxes in “Access:”

C) In the “Page” Block

  • check the “Provide Page View” box
  • in “URL:” enter a url
  • in “View Type:” select “Full Nodes”
  • uncheck “Use Pager”
  • check “Breadcrumb trail should not include “Home””
  • set “Nodes per Page:” to 1

D) Filters Block (Add Filter)

  • “Node: Published” “Equals” “Yes”
  • Node: Type “Equals” “Node: Front Page” “Equals” “Yes” ( Only if you want it as Front page, otherwise leave this) “Node: Created Time” “Is Greater Than” <put the date of your site creation for all nodes” Optional [to include or exclude specific node type(s)]: “Node: Type” “Is None Of” “page” <<== Select what works for your site E) Sort Criteria Block (Add Criteria) “Random” or Global Random F) Click “Save” See Demo on this page Method 2: If you are not using views then you can use this custom code to display random content. Check this page for details http://www.greenhughes.com/content/a-block-show-random-content-titles-dr… nid); echo ” “.l($node->title, $node->path).” (“.format_date($node->created, ‘custom’, “d M Y”).”) “; } ?> You can make some changes like this to display teasers. print l($node->title, $node->path).'< br />’; print $node->teaser

Leave a Reply

Your email address will not be published. Required fields are marked *