开发者

How to have different pagers on different pages on a drupal site

开发者_如何学JAVA

I understand how to create my own custom pagers using theme_pager() but how would I go about having different styles/configurations of pages on different pages.

For example.

Homepage style: [First] [< Previous] [1] [2] [3] [4] [Next >] [Last >]

Inner page: [< Previous] [1] [2] [3] [4] [Next >]

Views: [<<] [<] [1] [2] [3] [4] [5] [6] [>] [>>]

Note:

1st pager is the default pager

2nd pager has no first/last buttons

3rd pager uses images for buttons and has a different number of visible page links

My initial thought is to test for the path in theme_pager() to determine which style to render.

This doesn't feel right to me, is there a better way?


I would suggest that the easiest way to make the modifications that you are talking about is using CSS. Since you are not changing the number of items in pager list, the markup for these three pager styles could be identical.

User firebug to inspect the existing pager in your theme to discover where in your css the styles for the pager are coded. If you theme is already coding for them, then just modify the existing code. If the code is just pulling from drupal core, which is likely, then you can either override the entire css file by declaring a new one in your theme or just putting a new copy of the css rules in the css files of your your theme.

In order to make the different versions of the pager, you will have to identify some way of isolating the pagers that you want to theme differently. This could be done using the body classes which most drupal themes have, or using the class/id of the view/block for which you are trying to change the pagers. If you have a large number of views which need this pager style applied, then you could use something like skinr define the pager style, and attach the rule to the appropriate views/blocks.

Homepage Style looks like the default drupal stuff. Inner Page: you just need to add display:none for the first and last links. Views: For this, you will want to use css image replacement, like so:

/* set up defaults for all buttons */
.pager .next,
.pager .previous,
.pager .first,
.pager .last {
  text-indent:-9999px; /* hide text on the link */
  text-align:left;
  overflow:none;
  height:20px;
  width:20px;
  line-height:20px;
  dislay:block;
  background: transparent url(../images/pager-sprite.png) no-repeat 0px 0px; /* set a background image */
}
/* for each button, offset the position of the background sprite image */
.pager .previous {
  background-position: 20px 0px;
}
/* note that your sprite can also contain hover states for the images */
    .pager .previous:hover {
      background-position: 20px 20px;
    }
    .pager .next:hover {
      background-position: 0px 20px;
    }
.pager .first {
  background-position: 40px 0px;
}
    .pager .first:hover {
      background-position: 40px 20px;
    }
.pager .last {
  background-position: 60px 0px;
}
    .pager .last:hover {
      background-position: 40px 20px;
    }

** NOTE: this code will NOT work as is ... this is just a rough outline of the idea, and you will have to tweak it to make it work for the pagers. You should base your css selectors off of the selectors you find in drupal core or in the theme. Also, you may need to float the pager list items or remove the display:block property, or make other tweaks according to your needs etc.

If the views style pager is the most common, you may want to make this your default pager style, but note that if you do that, then your more specific style will have to unset all the other properties which have been set for this customized pager style.

Good luck ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜