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

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.

Related

Place an Edit Button on the view node page in Drupal 7

I don't use the Drupal Tabs because they interfere with my CSS but I need the functionality of the Edit tab to be on that screen so that a user can edit the node after reviewing it.
Any ideas on how to do this? Functions? tpl placement? Thanks!
You can do this in a custom module as follows.
In yourcustommodule.module you implement hook_preprocess_node(). In there you check if the user has permissions to edit the node and you set the edit link.
function yourcustommodule_preprocess_node(&$vars) {
if (node_access("update", $vars['node']) === TRUE) {
$vars['edit_link']['#markup'] = l(t('Edit'), 'node/' . $vars['nid'] . '/edit');
}
}
In the node.tpl.php template in the theme you print the edit link if it is available.
<?php if (isset($edit_link)) : ?>
<p><?php print render($edit_link); ?></p>
<?php endif; ?>
If you do not have a node.tpl.php template in your theme folder than copy the one from modules/node.
If you're using the Views Format "Fields", one of the fields that you can add is "Edit Link." It's pretty flexible; it will tell you what text to display in the link. That's probably the preferred option.
If you're not using the "Fields" format, it gets trickier, especially since you're already interfering with some basic drupal styling. I'd need more information about your View and your skill set to recommend a method that doesn't cause more problems.
As a sidenote: I learned Drupal theming from the outside in, and used to use CSS that would interfere with the underlying drupal mechanics like tabs and contextual links. I've moved away from that; I find very few cases where I need to interfere with native styling-- and for those I can use custom .tpl's to get around.
EDIT: Ah. If you're not using views, a custom page .tpl is probably the best way to go. If you're not familiar, the structure for any node edit link is '/node/<NID>/edit' (for clean URL's) or '/?q=node/<NID>/edit' for old-style URL's. Depending on how your path aliases are set up, '/<url-alias>/edit' may work as well but the previous ones are more reliable.
This link on drupal.org gives a few options.
I think u can write a theme file(.tpl) for u specific case and theme page in whichever way u want

Adding A Button Between post-content and Related Posts Thumbnail Plugin on WordPress

I am trying to add a button to my WordPress template. Basically, I have the post and then there is the Related Posts Thumbnails widget that appears. I want the button to go between the text of the post and the related posts thumbnail widget. The code in my 'Single Post' that contains all of this is as follows:
<div class="post-content">
<?php the_content(__('<em><strong>More:</strong> Read the rest of this entry...</em>', 'life-is-simple')); ?>
</div>
I know the Related Posts Thumbnails plugin falls within this code because it's at that place when I 'Inspect Element' on Google Chrome. I can't find how to edit the order of things within that div though. Any help would be greatly appreciated, thanks!
EDIT
Clarification: I am using the Life Is Simple WordPress theme although it has been custom editing quite a bit (mostly on the CSS side of things though).
That plugin is probably appending the output to the_content with a filter .
That means , that the output is being added to the_content automatically. it is a common behaviour.
You need to look at the pluginĀ“s admin interface to see if you can have an alternative way (I believe there is ) which is using a template tag. in that case, you should put the template tag after the div where the the_content() is .
EDIT I :
After a small dig, - in fact there is - you need to put
<?php get_related_posts_thumbnails(); ?>
Then the plugin should know by itself not to append to the_content.
For parameter passing, or if something is not working, go read their APi or help files.
You'll probably need to edit single.php or archive.php in your theme. If nothing is occuring there that looks familiar, it's probably using a loop. In which case you might find what you are looking for either in loop.php, loop-single.php, or loop-archive.php depending on what type of page you are on and how the theme was constructed. Add your button near where you find Read the rest of this entry...
With more information (such as what theme you are using), one might be able to help more as well.

Permalink-safe way to link pages inside footer.php

I am currently building a new theme for my site and am kind of stuck not knowing the proper way to link pages together. What is the proper way to direct visitor to another page if I were to write the link straight into footer.php?
Let's consider the following inside footer.php:
?>
A Link
<?php
That would work well up until I were to change my permalink structure to something else.
What is the proper way to do it(without using WP built in menus or anything similar)?
You can use get_permalink assuming your pages are in Wordpress.
See this link: http://codex.wordpress.org/Function_Reference/get_permalink
The above answer is 100% correct, but to save people some time when they stumble upon this question, I took the liberty of writing it out.
<?php echo get_the_title(12); ?>
This covers everything from hover text to dynamic page title, so if you decide to change "Contact" to "Contact Us," you won't have to remember to update the footer.php file.

Wordpress discontinuity between Excerpt and its 'more-button'

I'm building a custom Wordpress theme.In my index.php page i'm looping to display the excerpts for all of my blog-posts.
this is how I break the post flow:
//At first I place <!--more--> in my post-text where I want to break it..
the_content('more');
Now the point is I'd like to place the 'more' button not right after the excerpt.I'd like to place this button in another div containing other link-buttons (tags,comments-count ecc).
The only thing I came up with is using a span around the 'more' button (with absolute positioning).
Is there any better solution?
thanks
Luca
The fact that WP injects the read more link into excerpts, rather than just giving the formatted excerpt, has always been a problem for me, too. Especially since what surrounds the link is dependent on where the author placed it: inline or on a new line, before or after an image, inside or outside inline markup. Here's what I've done in the past -- I'm not sure whether this is the best solution but it should work...
get the raw, unformatted post content: $content = $post->post_content
get the excerpt by using explode("<!--more-->", $content).
run the excerpt through the the_content filter: $excerpt = apply_filters("the_content", $content[0]);
Balance the tags... $excerpt = force_balance_tags($excerpt)
On the whole, a better solution may be to ask authors to provide a text excerpt to go with each post rather than relying on this kloodgy method.

Drupal: Re-using faceted search blocks

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.

Resources