Using Hook Views Query Alter

0 Comments

Building a website I recently ran into an issue where I had HTML search facets interacting with Drupal views. The user would click on the facet and it would filter the view depending on the argument. I ended up implementing hook_views_query_alter. To make sure the values I wanted to filter on were in the view, I added the search facets into the view as fields. This automatically joins the necessary tables so that you don’t have to.

Implementing hook_views_query_alter requires two parameters, view and query, both are passed by reference. Since this hook is called for every view the first thing I did was check that I was altering the right query by adding an if statement that checks the view name. After that you're free to modify the query as you wish. In my example, I looped through the search facets and added them as where statements and arguments to the query.


function search_views_query_alter(&$view, &$query) {
  if($view->name == 'example_view_name'){
    foreach($parsed_url AS $key => $value){
      $query->where[0]['clauses'][] = 'profile_values_profile_' . $key . '.value IN ("%s")';

Nodequeue and Views Combination.

2 Comments

Sometimes it is really hard to show only the needed nodes in the needed order using views only.
Here are some examples when you need to give a Content Manager (CM) some control over the nodes that will be displayed by the view:
- you need to promote on the front page some content Item (for ex., some new Game) and want the CM to be able to change it through the UI any time he pleased

- you need to show the newest Games in the block (sorted by some date), but you need to give the CM ability to override this list and show a couple of Games of their choice at the top of the list (following by rest of the newest Games sorted by a date)

- you need to show a list of Items of some Type, but to make sure that some of the Items (from some "black list") will never be included into this list.

The Nodequeue and Views modules will be a very useful combination here.

3 Techniques I've Used Recently - In both pure CSS and JS versions!

0 Comments

Sticky Footer

CSS Solution:
www.cssstickyfooter.com/
The least buggy css-only sticky footer I've found - just arrange your page.tpl accordingly, add the CSS, and it works!

JS Solution:
www.css-tricks.com/snippets/jquery/jquery-sticky-footer/
This one is for the times when you can't create the proper page structure but still need that footer stuck to the bottom of the page.

Imagemap Rollover

CSS Solution:
http://www.noobcube.com/tutorials/html-css/css-image-maps-a-beginners-gu...
I used this recently to create a map that would allow users to select different regions as taxonomy terms - it is a bit intensive to set up, but the hover tooltips make it worth the time.

JS Solution:
http://davidlynch.org/js/maphilight/docs/
For pin-point accuracy. (See 'A map of the USA').

Tooltips

CSS Solution:
http://www.kollermedia.at/archive/2008/03/24/easy-css-tooltip/
Implemented a sleeker-looking version of this tooltip after getting buggy JQuery tooltips on a JS-intensive page.

JS Solution:

Quick Tip: Seamless scrollbars without page shifting

2 Comments

Just a quick tip on improving the user experience of your site. By default, browsers are smart enough to figure out if parts of the page exceed the visible boundaries of the browsers' window. On the other hand, when you're viewing page that you can interact with (be it expanding a block of text, or loading a new tab via AJAX), often times the page's boundaries will change (i.e. the height of the page will increase/decrease) and the scrollbars will be added/removed as a result or more/less visible content.

Although this default behaviour is fine for most static sites, it starts to take away from the user experience when the page shifts left 20px and right 20px each time a scrollbar is added and removed, respectively. It's difficult for the end user to focus on what content actually changed versus what stayed the same. You'll notice a more seamless experience when switching tabs, and dynamically loading content.

By simply adding a CSS rule to the html (or body) tag, you can eliminate this so-called page jitter that happens each time the content is modified on the page.

In your main .css file, add the following code

html {
overflow-y: scroll;
}

View and CCK pitfalls for Drupal beginners

2 Comments

View and CCK are great for doing a lot of cool things on Drupal sites. However, at the same time there are a few things beginners should beware of when using View and CCK.

1) Filter out those 'not published' contents -- this is probably mentioned in every tutorial, book and video... yet once in a while someone will forget to do it. If something is not set to 'published' you should avoid showing it on your live site.

2) Save that view or you will lose it -- Sometimes beginners will mix up the 'update' button with the actual 'save' button at the bottom. Update is for applying the current changes in your field, filter etc. Nothing is actually saved until you press that 'save' button. Even if you can see the changes in the preview it doesn't mean your changes are saved.

3) Which view are you editing? -- After you saved a view the focus shifts back to default view. If you have a page and a block view under the default view and only want to edit one of them then make sure you select the right one before making changes again.

Drupal Base Themes

2 Comments

Using a base theme when it comes to creating a theme for your Drupal site can be a polarizing issue. On the one hand, some people swear by using Garland as a starting point, customizing it until it looks nothing like the original theme at all. However, I personally prefer the other approach – start with a stripped back base theme and build from there.

There are numerous benefits for using a base theme to build your new Drupal theme. Depending on which base theme you go with, some of the benefits include:

  • -Sensible CSS resets, so your HTML elements are consistent across browsers and platforms
  • -Included templates, meaning you get a great set of templates for your page, node, blocks etc to work with and build off.
  • -Most base themes will include additional classes, making your CSS more concise and easier to write.
  • -Additional functionality, such as block configuration links and module integration.
  • -Out of the box compliant XHTML and CSS.

While there are numerous benefits to using a base theme, there are many people who will offer counter-arguments. These may include:

Time display and manipulation in Linux

0 Comments

We use timestamps a lot in web development, whether using Drupal or not. Sometimes during debugging we may want to know what is the actual human readable time for a timestamp (eg. 1279566878). This is easy to achieve in Linux, without writing any PHP code.
date -d@1279566878
Simply use the command in shell and you will see something like Mon Jul 19 12:14:38 PDT 2010, which gives the human readable time for the Unix timestamp 1279566878.

Another thing we'd like to do sometimes is to change the server time and timezone. In Ubuntu, you can type the command
dpkg-reconfigure tzdata
or
tzselect
and then select the timezone you want. Or you can do so by modifying the timezone file /etc/localtime
ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime
This would set the timezone to America/Toronto.

To change the current server time, you may use the command
date 052018302010.15
which would set the time to May 20, 2010, 18:30:15. The format of the time string is nnddhhmmyyyy.ss where
nn: 2-digit month (01 - 12)

Rounded Corners With jQuery

3 Comments

Rounded corners have become very popular and could be very easy to implement using CSS3. However as we know, some widely used browsers won’t give support to CSS3, making our life more complicated and our code more ugly.

Luckily, there are ways to get around for browser limitations! There are numerous CSS-only techniques that vary in complexity and flexibility. In addition to the numerous javascript techniques that are usually easier to implement. This is my favorite one:

The “jQuery Corner Plugin” (jquery.malsup.com/corner/) will add divs to the element with a solid color background to hide the original corners and create the illusion of rounded corners. What I really like about the “jQuery Corner Plugin” is that it detects if your browser gives support to CSS3 and will use the appropriate CSS if possible.

Here’s how to implement it:

Pros of Drupal being open source

1 Comment

I compiled a list of some pros about Drupal being open source.

Pros:

1. Contributed modules
Like the Apple App commercials "There's an app for that," ...there normally is a module for that too. It might not be exactly what you want but it does give you multiple community options.

2. Free
I love free things, no licenses, no sign up fees, no signing up for newsletters, its just there to download and play with. Install it as many times and in as many locations as you need. There's no need to count, track, or monitor for license compliancency.

3. Easily Changeable Code
you can fix and tweak problems according to your needs. You can also learn about how the system works itself by looking at the core code. This is a huge win over closed sources where you don't even own the code.

4. Community
Lots of resources and eyes from other people. You can find help and contributions from other people, and not just one company.

5 Musician Websites using Drupal

3 Comments

Drupal has gotten really popular, mostly because of its easy to use interface and modular design. Creating custom themes are also easy to create with a little Drupal knowledge. If design is not your thing, there are many pre-built themes available for download if you do a quick search.

The popularity of Drupal has also caught the attention of many artistic individuals. In this case, I'm talking about musicians. Even though it may not be the artists themselves that create these sites, the sites were still made to represent the artist. These sites show the flexibility of Drupal and how it may be tailored to anyone's needs. At first glance, it may not look like a Drupal powered site, but I'm sure many developers will be able see the difference.

Ozzy Osbourne's Offical Site
Ozzy Osbourne's Offical Site

  • 1 of 9
  • >