Drupal: Re-using faceted search blocks - drupal

The faceted search module in Drupal creates a set of blocks for each new faceted search environment (current search, guided search, related, etc).
If you were to create a faceted search environment for e.g. books, you could set it up with a base path browse/books and a start page as browse/books/results. To display the faceted search blocks, you'd then set the Page Specific Visibility settings for the block as 'Show on only the listed pages' and the actual pages as
browse/books
browse/books/results*
Question: I would like to re-use the 'guided search' block on a different landing page. The landing page should display a list of available search terms (sidebar-left) and show a view over the rest of the page.
So far, simply adding a different path to the list of 'show on only the listed pages' has no effect.

One way of almost getting there is to add a new custom block and then trying to display the actual block using the following:
<?php
$block = module_invoke('faceted_search_ui', 'block', 'view', 'xxxxx');
print $block['content'];
?>
Where xxxxx is the id of the faceted search environment, for example 1_guided. Problem is that looking at function faceted_search_ui_block(...) will only get you so far. The block will only be rendered if the environment is in the correct state, which, unless it is a known faceted search environment supposedly running under the associated path, it is not.
So, doesn't look like it is possible.

Drupal veterans would likely be able to offer better, cleaner and more correct solutions, but the following works for me:
I added a new block which runs the following PHP:
$env = faceted_search_env_load ( $fs_env_id );
if (!$env->ready())
{
$env->prepare();
$env->execute();
}
faceted_search_ui_add_css();
$env->ui_state['stage'] = 'results';
print faceted_search_ui_guided_block($env);
$fs_env_id depends on your setup. The links generated by the API will link to the actual faceted search environment paths, as expected.

Hmm. I am not sure if this is what I was looking for or not-
Here is what I am using now. I don't know if it is exactly what your looking for but you can render the facets on any page that is applicable. (the facets are supposed to show on)
For me it is search results via views.
I am rendering a block, with all my search facets in one block.
<div class="xfacet">
Something here
<?php
$block = module_invoke('facetapi', 'block_view', 'xxxx');
print render($block['content']);
?>
</div>
<div class="xfacet">
Something there
<?php
$block = module_invoke('facetapi', 'block_view', 'xxxx');
print render($block['content']);
?>
</div>
I just control where the block shows.I'll follow up with a link after launch.

Related

How to hide title from page node Drupal

I'm trying to remove the title of a page node on Drupal. I have this page:
And I want it to look like this:
As you can see, I want the title to be removed, but only for taxonomy terms. If I try to erase it using CSS, I erase al page-titles, so I wanted to use this module, that allows administrators to auto-generate node titles and hide it.
I go to structure -> type content -> my type content, and edit it. I activate the module, and I want to auto-generate titles depending on the node category. I think it should look like this, but it doesn't work...
Any ideas why?
EDIT: Sorry, I forgot to say: yes, when I activate the module, use it, and select the category as the auto-generated title, it works. But it doesn't hide the title...
It also launches this mistake:
Use Exclude Node Title module.
https://drupal.org/project/exclude_node_title
Setting for this module:
Click on Module->Exclude node title->configure
Home » Administration » Configuration » Content authoring
Select All nodes from Basic Page
Check Full Content for hide title from all cms page except home page
Check Teaser for hide title from home page.
If you want to remove the title, you should look into overriding the page and node templates.
page.tpl.php and node.tpl.php
All you need to do is click "View Source" on both of those and copy them to your theme folder. From there you can modify both as required.
From what I can gather, you'll want to remove the print $title from your node.tpl.php.
Have the similar issue before, as far as I remember, I just added some if statement to the code:
<?php if (blah-blah-blah): ?>
<h2> <?php echo $title; ?> </h2>
<?php endif; ?>
Hope, it'll give you a clue.
Some other thoughts: you can make an if statement or rewrite it not only in page.tpl.php but create some specific page-node-type.tpl.php file and overwrite only its $title, or you can try to customize page's output via Views/Panels modules as well.
Also, could you please make more clear, what title do you want to remove? Page title or node title? And it should be removed only when you are looking nodes associated with some taxonomy term (in other words, when you are on /taxonomy/term/n page), am I right?
By using the Context module, you can add classes to the body so you can target just the taxonomy pages in CSS.
Using Context module to set body classes
Sorry guys, it was as easy as hide title tag on "manage presentation"...
You are all right on your responses, but they were not exactly what I needed... thanks!
Use Exclude Node Title module.
https://drupal.org/project/exclude_node_title
another nice solution for specific nodes, is to use the standard $title_prefix/suffix vars, which should be implemented by every theme. using the standard class element-invisible in page preprocess ..
like:
/**
* Implements hook_preprocess_page().
*/
function YOUR_THEME_preprocess_page(&$variables) {
if (isset($variables['node']) && $variables['node']->nid == 1) {
$variables['title_prefix'] = array('#markup' => '<div class="element-invisible">');
$variables['title_suffix'] = array('#markup' => '</div>');
}
}
Every page should contain a heading.
You should always maintain a structured hierarchy of headings within any web page. You should never have a blank heading or even hide it with display:none;. Hiding any content which isn’t viewable by your visitors but is by search engines is against Google’s guidelines as your intention is to only manipulate search engine results by including it. Restyle a H1 so it fits into your design is the best option.
If you still have to hide it then a better option would be to either create a template for that node, content type or page and simply not print the heading.
Or if you want to use CSS then use position:absolute so the heading doesn’t use any space where it is located in the page and text-indent:-9999px; so the text is moved off the screen and no longer visible but at least can be read by screen readers and search engines.
This is how I did it, Switch statement
// Get the name of node
$node_name = node_type_get_name($node);
// Then just add the content types you wish to exclude by overwriting the // $title object with an empty string
switch ($node_name) {
case 'Home page':
$title = '' ;
break;
case 'Event':
$title = '';
break;
case 'Offer':
$title = '';
break;
}

Displaying a Drupal content type field outside of a node

I have created a custom field on a content type in Drupal 7 which I need to display outside of the node, in a separate area on the page.
Similar to how the $title variable works (in which you can place this where you like in the page.tpl.php file) I would like to be able to create another variable called $subtitle which would call the data from the current node and allow me to print out the variable in an area on the page.tpl.php file.
I've seen a view examples seeming to use views and blocks to accomplish this task, but that seems a bit excessive and wondered if there was an easier way.
There is an easier way, you do need to bear in mind though that not every page is a node page, and not every node page will be of the right content type so you should be selective. Just add this to your theme's template.php file:
function mytheme_preprocess_node(&$vars) {
$node = $vars['node'];
if ($node->type == 'my_type') {
$vars['subtitle'] = $node->field_my_field[LANGUAGE_NONE][0]['value'];
}
}
Then in page.tpl.php you should do something like this:
if (isset($subtitle)) :
echo $subtitle;
endif;
Make sure you clear your caches (at admin/config/development/performance) once you've implemented the hook in template.php or Drupal won't pick it up.

How to add search box to drupal page contents (404 page)

I have a theme where search box is hard to find.
Before redesigning it, I'd like to add another, bigger search box to 404 page.
The only solution I found is render search block:
<?php
$block = module_invoke('search', 'block_view', 97);
print render($block['content']);
?>
This is not good solution because one have to find block number first.
How to use search_box() function properly?
Maybe you'd want to try using http://drupal.org/project/search404? I'm not sure if you can disable automatic searching on a 404 page but it's very close to what you are needing without custom code.

Help with Drupal Search Form Display

When displaying the search form in my header, what is the preferred method to use if it cannot fit into my header region??
should I...
create a custom region?
use some kind of 'print $search_form'
drupal_get_form()??
use the theme() function??
please help! I'm new to Drupal and trying to figure out the best 'Drupal Way' of doing things.
Depends on how you want to define or maintain the search form. If you think of it as part of the theme (that is, it's as static as the page background or colors), consider just using the following in page.tpl.php:
<?php if ($search_box): ?>
<?php print $search_box ?>
<?php endif; ?>
This is de-facto the Drupal Way: if your theme didn't modify the page variables, you get $search_box for free in page.tpl.php. Adding the conditional also lets site maintainers turn it off in the theme settings and specify permissions for it.
If you want to give site maintainers the ability to move it around from region to region, consider using the Search block. This way it can be utilized just as any other block on your site. This would also be considered Drupal Way-ish: you get the block for free if you enable the Search module.
If you want theme the forms, override search-theme-form.tpl.php if you use the first method, and search-box-form.tpl.php if you used the second. Both templates can be found in modules/search.
You could do any of those. You could create a custom region, and use CSS to change the display. You could alter the form with preprocessing hooks or hook_form_alter.
Depends on whatever is easiest for you.

Show secondary links in views only

I'm building a site in Drupal and I only want to show the secondary links on the
pages that use the Views I've created. I tried using the $secondary_links variable
in the views-view.tpl.php but the variable is null. How can I achieve this?
The secondary links are as mac correctly writes only available in page.tpl.php, but if I understand you correctly, the best solution is not getting the secondary links into your view.
With your theme, the secondary links, will most likely be printed out where they should, regardless of what is being displayed, be it your views, nodes, the front page etc. Views are displayed and everything else you render, is wrapped in the page template, that controls where menus are located, regions and other fun stuff.
Now, if you don't want to alter this, the location of the menus, their styling and this stuff, you shouldn't be printing the secondary menu in your views template, you shouldn't be doing anything with it at all.
The solution is simple
It's using something that mac mentioned but in a different way: preprocess function. These functions are used to in your template.php file, to add some logic to your variables. You can alter variables or remove them altogether. What I would do, would simply be to remove the primary links, by setting the value of $primary_links to an empty text string.
This would effectively remove the primary links, so only the secondary links are displayed. You could also display the secondary links as the primary, but this might cause confusing to your users. You just need to add some logic to control when this should happen and you are set.
Have you activated the secondary links from the theme settings? That would be:
http://example.com/admin/build/themes/settings/name_of_your_theme
I believe once you have activated the option, the variable will be populated.
EDIT: Thinking a second more, I would also comment that I am not sure if the primary and secondary links are passed to the views templates. I believe those are passed to the page.tpl.php file instead. If I am right, and for some reason you want to add that variable to those passed to the views template, you will have to use a preprocess function, like explained here.
EDIT #2: Indeed if you only need the secondary menu used in a specific views template, another approach would be to simply call menu_secondary_links() from within the template. This is not the most elegant solution ever, as it puts in a theming element something that should belong somewhere else, but it's up to you to make the call whether that menu in the views is a core functionality or a styling element.
HTH!
You can use the following code to show secondary menu on any view
function YourTheme_preprocess_views_view(&$vars)
{
$menu_sec = menu_navigation_links('menu-secondary');
$vars['custom_menu'] = theme('links__menu-secondary', array('links' => $menu_sec));
}
or you can even use other preprocess function depending upon your needs.
Further you can call it on .tpl.php file using:
<?php
$menu_sec = menu_navigation_links('menu-secondary');
print theme('links__menu-secondary',
array(
'links' => $menu_sec,
'attributes'=>array(
'class' => array('nav', 'nav-pills', 'p-f-subfilter'),
)
)
);
?>

Resources