0

I want to add drop-down list that allows users to select which page they want to visit.

How can I accomplish this?
What code should I use?

  • 1
    It is rather difficult to understand what is being asked here. Please expand the question, and make clear what you are trying to accomplish. – kiamlaluno Mar 27 '11 at 3:31
  • i am sorry.,i have explainned the question clear. namly, i want to add a specific location function to the page.which using an input textbox. the user enters the number that he wants to vist to the textbox – enjoylife Mar 27 '11 at 3:49
2

If you want to replace the whole site pager with a drop-down list, you should write a custom module (see 1 and 2). If you want to show it only for some pages, you just invoke the module (see 2):
1. Declare this in the template.php of your theme (replace YOURTHEMENAME and YOURMODULENAME with the appropriate theme/module name):

function YOURTHEMENAME_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  global $pager_page_array, $pager_total;
  // Calculate various markers within this pager piece:
  // current is the page we are currently paged to
  $pager_current = $pager_page_array[$element] + 1;
  // max is the maximum page number
  $pager_max = $pager_total[$element];
  // End of marker calculations.

  return drupal_get_form('YOURMODULENAME_pagerform', $_GET['q'], $pager_max, $pager_current);
}


2. Create a custom module, adding the following code to the YOURMODULENAME.module file:

function YOURMODULENAME_pagerform(&$form_state, $path, $pager_max, $pager_current = 0) {
  $form = array();  
  $pagers = array();

  for ($i=0;$i<$pager_max;$i++) {
    $pagers[$i] = $i+1;
  }

  $form['pager'] = array(
    '#type' => 'select',
    '#title' => t('Current page'),
    '#options' => $pagers,
    '#default_value' => $pager_current,
    '#attributes' => array('onchange' => 'this.form.submit();'),
  );
  $form['path'] = array(
    '#type' => 'value',
    '#value' => $path,
  );
  $form['submit'] = array(
    '#type' => 'submit', 
    '#value' => t('Submit'), 
    '#attributes' => array('style' => 'display: none;') 
  );

  return $form;
}

function YOURMODULENAME_pagerform_submit($form, &$form_state) {
  drupal_goto($form_state['values']['path'], 'page='.$form_state['values']['pager']);
}

p.s. The code was quickly written in browser without any debugging, so may be some errors happen, but it's should give "idea".

  • If you want to show it only for some pages, you just invoke the module , i don't know how to do this. thank you. – enjoylife Mar 28 '11 at 2:15
  • i don't want to replace the whole site pager with a drop-down list,i only want to add a drop-down list after the pager. how to alter the code? – enjoylife Mar 28 '11 at 3:59
1

Try using the Jump module. It's documentation is here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.