Hi,

I've got a view which filters the content by node type, and have exposed the filter so that the user is able to select the node types they want to view. However, there are certain node types I do not want to include in the list so I'm wondering if there's some way of selecting which node types to display to the user? Currently, in the node type filter I have selected a number of types I want to display and have set the operator to "is one of", but this has no effect on what is displayed in the exposed filter (which simply displays all node types).

Many thanks for any feedback.

Comments

mooffie’s picture

stormer’s picture

Thanks so much for that. However, I am stumped as to what to do with this snippet from the solution:

/* if you need to get the id of your filter, you can find it there:
     echo '<pre>';
    var_dump($form);
     echo '</pre>';

Where do I enter this text in order to get the filter ID?

Thanks again.

mooffie’s picture

I've just expanded the comments on that page. I hope they're clearer.

stormer’s picture

Ok, so I've got the following code in my template.php

 <?php
// Replace "VIEWNAME", in the function's name, with
// the name of your view.
function theme_views_display_filters_newfront($view) {
  $form = drupal_retrieve_form("views_filters",$view);
  unset($form["filter2"]["#options"]["page"]);
  unset($form["filter2"]["#options"]["biography"]);
  /*
  Filters (that is, fields) on the form are given sequential ID:
  'filter0', 'filter1', 'filter2', ...

  Above we assumed the the filter select-box is the first on the
  form and hence has a 'filter0' ID. If your filter is not the
  first on the form, adapt the ID accordingly. You may wish to do:

  echo '<pre>';
  var_dump($form);
  echo '</pre>';

  and inspect the output to find out your filter's ID.
  */

  $result = drupal_process_form('views_filters', $form);
  $output = drupal_render_form('views_filters', $form);
  return $output;
}
?>

The filter I wish to affect is the third in the list ie. filter ID 1. The view name is newfront. However, once I've done this and go to acces my site I get the following error message: Parse error: syntax error, unexpected '<' in /nfs/c02/h02/mnt/26164/domains/dev.xscriptorium.com/html/themes/garland/template.php on line 56

I can't figure out what I'm doing wrong.

mooffie’s picture

Parse error: syntax error, unexpected '<'

You're not supposed to include the <?php ... ?> tags. These tags are used here on drupal.org's website to get syntax highlighting, and are usually not meant to be copied (I fixed that page to warn against this).

stormer’s picture

thanks for bearing with me.

Anyhow, I've removed the tags at the start and at the end of your code and whilst I'm not getting an error message, it's still not working - my exposed filter still includes the "biography" and "page" node types.

mooffie’s picture

Add the following line to the start of your function. It will tell you that the function indeed gets called:

drupal_set_message("I've been called!");

Add the following line right after the "$form =" line to verify that 'filter2' indeed stands for the select-box:

drupal_set_message('The selectbox: '. print_r($form["filter2"], 1));
stormer’s picture

Well, that's certainly working - the two messages are showing up just fine. So what could be going wrong? Incidentally, I'm testing this on two versions of the same site, one web-based and the other running locally on my laptop, with the same results.

mooffie’s picture

the two messages are showing up just fine

Can I see the second message? Use http://pastebin.com.

stormer’s picture

Sorry, when I said both messages I meant both lines (see here: http://dev.xscriptorium.com/)

mooffie’s picture

xscriptorium.com

Does the form I see on that page, 'Select Type', have anything to do with our discussion? Because if it is, the selectbox is the first field on that form --not the third-- so it's 'filter0', not 'filter2'.

The selectbox:

No, this message isn't fine. No details about the seletbox are printed, so the selectbox probably isn't the third field on the form.

stormer’s picture

Hi,

that was it!!!!!!!!! Well, part of it. So the problem was that I thought the filter I was after was the filter in the View (as opposed to the exposed filter). So I changed that but again, it wasn't working. Then I realised that perhaps the node type needed to be listed by its cck type as opposed to name - as such "biography" was actually "bio"... and that did it.

The message "the selectbox:" is still not showing anything but I guess we're no longer concerned with that. So ,success!!!

Thanks so very much for walking me through this, I really appreciate it.

nard0207’s picture

Hi!
I have inserted the following code [with some modifications for my site] into the template.php in my danland folder.
It seems that the function is not called because when I use drupal_set_message nothing appears.
How can I solve this problem? Thanks.

stormer’s picture

Hi Mooffie,

got another question in relation to this one - how would I add other views to the list or would I simply duplicate all the text for each view I want affected?

Thanks very much,

Ole

mooffie’s picture

I'm nost sure I understand the question.

If I'm guessing correctly, you want to display several different views on a page, all affected by a single 'node type' exposed filter. Is this correct?

stormer’s picture

Hi Mooffie,

sorry for the late reply.

If you have a look at http://dev.xscriptorium.com and click on the exposed 'Select Type' button, you'll notice that it only shows 4 items. Now, if you go to http://dev.xscriptorium.com/topranked and click on the button you'll notice that there are a whole bunch of additional content types listed in there. So basically I need to include this view (as well as http://dev.xscriptorium.com/lists) in the template.php so that the buttons show the same list as the first button.

Thanks in advance.

Incidentally, thanks for pointing me in Caroline's direction - she's been helping me out with a couple of projects and is doing a fantastic job.

cheerio

Ole

mooffie’s picture

If you have a look at [...]

I need a name/password to login, but nevermind, I think you explained the problem well:

So basically I need to include this view [...] in the template.php so that the buttons show the same list as the first button.

If I understand correctly, the current template.php handles only the 'newfront' view (that's ok: it's supposed to). You want it to handle the 'xyz' view as well.

So make a copy of the 'theme_views_display_filters_newfront' function, but rename that copy to 'theme_views_display_filters_xyz'. (Basically, it amounts to what you'd have done if you read this thread anew and applied the instructions to the 'xyz' view instead of to 'newfront'.)

Incidentally, thanks for pointing me in Caroline's direction - she's been helping me out with a couple of projects and is doing a fantastic job.

:-)

stormer’s picture

Brilliant!!!. That worked a treat. Thanks very much for your help.

Ole

plan9’s picture

I have the same issue. The code mentioned here works to hide node types from the drop down menu - but if a user chooses the 'ALL' option everything, including the node types that should be hidden - is displayed.

It is possible to remove the ALL option with: unset($form["filter0"]["#options"]["**ALL**"]);
In fact this is what I am doing - although it would be much better to be able to return all of the allowed node types in the view.

If I've understood correctly this is not currently possible with the views module.