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

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

Related

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.

How to disable page's title in wp-admin from being edited?

I have a wp-network installed with users that can create pages in each site.
Each of those pages get a place in the primary menu, and only one user have permission to create all this menu.
I want to create a user only to be able to edit the content of the pages, but not the title.
How can I disable the title of the page to be edited from the admin menu for a specific user, or (far better) for a capability?
I thought only a possibility, that's editing admin css to hide the title textbox, but I have two problems:
I don't like to css-hide things.
I don't know where is the admin css.
I know php, but don't know how to add a css hide to an element for a capability.
You should definitely use CSS to hide the div#titlediv. You'll want the title to show in the markup so the form submission, validation, etc continues to operate smoothly.
Some elements you'll need to know to implement this solution:
current_user_can() is a boolean function that tests if the current logged in user has a capability or role.
You can add style in line via the admin_head action, or using wp_enqueue_style if you'd like to store it in a separate CSS file.
Here is a code snippet that will do the job, place it where you find fit, functions.php in your theme works. I'd put it inside a network activated plugin if you're using different themes in your network:
<?php
add_action('admin_head', 'maybe_modify_admin_css');
function maybe_modify_admin_css() {
if (current_user_can('specific_capability')) {
?>
<style>
div#titlediv {
display: none;
}
</style>
<?php
}
}
?>
I resolved the problem, just if someone comes here using a search engine, I post the solution.
Doing some research, I found the part of the code where the title textbox gets inserted, and I found a function to know if a user has a certain capability.
The file where the title textbox gets added is /wp-admin/edit-form-advanced.php. This is the line before the textbox
if ( post_type_supports($post_type, 'title') )
I changed it to this
if ( post_type_supports($post_type, 'title') and current_user_can('edit_title') )
That way, the textbox is only added when the user has the capability called "edit_title"
When this IF block ends few lines after, I added:
else echo "<h2>".esc_attr( htmlspecialchars( $post->post_title ) )."</h2>";
To see the page title but not to edit it, when the user hasn't got "edit_title" capability.
Then I had already installed a plugin to edit user capabilities and roles, wich help me to create a new capability (edit_title) and assign it to the role I want.

Show Link If Views Basic UI is Editable

I'm using Views Basic UI in Drupal 6 to allow users to edit a views header and title. I would like to cut back on the number of view templates that I have, so that in the future if I need to edit, I would only have to make changes in one place.
To do that, I'd like the views template "views-view--page.tpl.php" to provide a link only if the view is editable as defined by the Views Basic UI: Edit Settings module. I'm just not sure what the code should look like. I think it'd be something along the lines of
<?php if (in_array('views_basic_ui'): ?>
<div class="page-edit"> ...
I don't know what to put in that if statement though, in order to say "only print this button if the view has been selected as editable in the views basic ui settings". I'm guessing somebody that reads/writes code better than me could figure it out pretty quick, but I'd appreciate any help I could get.
Thanks.
ps - it's worth mentioning that the users will not have local tabs, so they won't see the 'view' and 'edit' tabs provided by the module.
Not sure exactly what you need, but the bellow code will check if the user has access to the destination and prints the edit link. But better to go with Views' native edit links. Not sure why you can't use them.
<?php
$path = "admin/build/views/edit/VIEW-MACHINE-NAME";
$item = menu_get_item($path);
if ( $item['access'] ) {
print l(t('Edit'), $path);
}
?>
replace VIEW-MACHINE-NAME with View's machine name.

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.

Resources