1

I'm trying to create a pagination type menu item that would allow the user to see older/newer content. The wildcard would represent the multiplier that would set the range from which the content is culled. This is the array created within my hook_menu() implementation:

$items['cars/%'] = array(
    'title' => 'cars',
    'page callback' => 'cars_car_view',
    'page arguments' => 'page',
    'access callback' => TRUE,
);

and this is my page callback function:

function cars_car_view($page) {
    print $page;

    // Code
}

But when I print the $page variable, only "cars" is printed, rather than the number. I've read through the documentation on hook_menu, but can't seem to figure out what I'm doing wrong or what I should be doing instead. Any help?

2 Answers2

4

You have to use array in page arguments. array(0) refers to cars array(1) refers to wildcard

$items['cars/%'] = array(
    'title' => 'cars',
    'page callback' => 'cars_car_view',
    'page arguments' => array(1),
    'access callback' => TRUE,
);
Balaji
  • 850
  • 7
  • 15
  • I had used the array() in page arguments, but it wasn't working either. I realized eventually that the problem was that I was using the same page callback function as another page that didn't accept arguments. One was to be a landing page (equal essentially to cars/0). Fixed it by creating two identical functions, but one that accepts arguments and one that doesn't. Would love a more elegant solution though if one exists. – Brian Crawford Feb 16 '15 at 16:19
0

If you want get argument from url you can used arg() function or drupal_get_query_parameters().