Help with Drupal Search Form Display - drupal

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.

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

Including php files in wordpress

I have a plugin that makes a custom content type and enables that custom content type to display its own archive pages. That is, this custom content type will display with archive-customtype.php rather than archive.php.
I don't want this, however. I want archive content to display in the same way whether it's a post or a new content type.
I can't just remove archive-customtype.php because the plugin expects it to be there. Can I remove everything from that file and simply say:
<?php include("archive.php"); ?>
That works but I want to make sure this is the best wordpress way to do it. Any thoughts?
I would use locate_template or get_template_part rather than include. You should be able to do get_template_part( 'archive' );-- note that there is not file-type ending.
It worries me that it doesn't work if you just remove archive-customtype.php. As you realize, archive.php should just work. It should be the fallback template. That the plugin requires this file is odd and makes me worry that something will break, or is broken and you haven't noticed.

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.

Insert a plugin manually into wordpress page

I am working in worpress front page.
I want to add a plugin to the page at a specific location manually but adding the code to the page myself.
I basically want to include a plugin in a certain page on a certain location. So I'm create a div...
<div id="plugin-holder">
**Plugin-will-appear-here-with-this-code**
</div>
Don't anyone know how this is done please?
Thanks
If you're wanting a plugin to appear somewhere, you'll be looking for "shortcode" functionality.
This is actually surprisingly easy to code, check out the examples in the Codex under Shortcode API - ie:
function bartag_func( $atts ) {
// ... do more things here ...
return "text to replace shortcode";
}
add_shortcode( 'bartag', 'bartag_func' );
Once you've called these functions you can use [bartag] in code and it will run your function and replace the shortcode with the generated text your function returns.
If you're adding shortcode functionality to your site, it generally makes most sense to code a really simple plugin and put it in that. The reason why this works best is that, over time, it's really easy to forget and upgrade a theme by mistake (or even change to a new theme) and thus break your site by losing your custom code in your former functions.php. Surprisingly, this is pretty easy to achieve and only requires some specially formatted comments at the top of your plugin file and a little common sense in coding - there are many tutorials and "how to"s around!
Here's a useful shortcode tutorial: http://www.reallyeffective.co.uk/archives/2009/06/22/how-to-code-your-own-wordpress-shortcode-plugin-tutorial-part-1/
You should add the relevant plugin code to functions.php.
I suspect you'll want to use some conditional tags, like is_home() to pinpoint your location. But maybe not, depending on what you are trying to do,
Also, if you're trying to to insert from a pre-existing plug-in, make sure you remove the register_activation_hook or activate_pluginname action.
If your plugin supports a sidebar widget you can simply "widgitize" the div tag that you wish to insert the plugin into.. Google the term and you are gonna find many resources.

Drupal: include small form in page.tpl.php

In my template.php i have a function_name($form) with some basic html markup and a drupal_render($form['mail']) and drupal_render($form) that returns $output;
I'd like to include this small snippet & form in my page.tpl.php. Everything else in page.tpl.php is printed out as a single variable, so I'd like to do that for the $output of the function above.
What is the best way to do this?
In theory you could append the output of the function to the $content variable.
However, It sounds like you have something which may be better off as a block, rather than something that exists in your template.php.
You can quite easily create a module with a single block (which would be your function). You could add this where ever you wanted and easily turn off and on (and all the other block admin goodness) without having to change the code.
The other thing you could try out is the webform module. It's a nice module that has a large feature set, saving you the trouble of having to create a module. You can have a webform block which you can stick on that particular page (restrict to page).
I also see that your form is called mail. Webform also allows you to email form submissions. In addition, it provides a nice interface to see what users have submitted.

Resources