Wordpress Twenty Eleven Template Page Issue - wordpress

I'm running into a curious problem with the Twenty Eleven theme. I have copied the theme to my own folder (using it to create a new theme...I should have gone the child-theme route but...I didn't). So far all is good. Now I want to create a custom verson of the sidebar-page.php template.
I grab the template page that has a sidebar: sidebar-page.php
I make an exact copy, changing the name to sidebar-page2.php
I change the template name of the new file from "Sidebar Template" to "Sidebar Template2"
I upload (no changes to the structure of the template)
I change a page's template to "Sidebar Template2" from "Sidebar Template"
Load the page, it looks different. It's almost as if the content is more centered, the H1 tag for the page is moved down, to the right and is bigger.
I can't find any info on this. I found one post where someone had the same problem (on another site) but no solution.

I had the same problem and found the answer on another page:
Basically, the problem is that it's adding another class to the body tag, in this case the 'singular' class. So here's something you can add to your functions.php file to filter that class for the sidebar-page2.php template file (or any other file, just replace sidebar-page2.php).
add_filter('body_class', 'adjust_body_class', 20, 2);
function adjust_body_class($wp_classes, $extra_classes) {
if( is_page_template('sidebar-page2.php') ) :
// Filter the body classes
foreach($wp_classes as $key => $value) {
if ($value == 'singular') unset($wp_classes[$key]);
}
endif;
// Add the extra classes back untouched
return array_merge($wp_classes, (array) $extra_classes );
}

My guess is that you have an unbalanced tag somewhere. Check to see that the is where you expect it. You may want to use Firebug or Chrome's Html viewer to verify the html is exactly the same.
Another possibility would be that the CSS is looking for a specific tag structure to which to apply styles. Again, Firebug or Chrome could help you locate this.
Without posted code, however, it would be difficult to answer it directly.

Just had the same problem!
It seems that the css classes on the body tags are different. On the copied template, the page has singular class, while the actual sidebar-page template doesn't. Clearly, there must be some logic in the theme that checks if the sidebar-page template is being used or not and alters the css classes. Not sure where this logic is in the theme yet, though.
sidebar-page template:
<body class="page page-id-2 page-template page-template-sidebar-page-php logged-in admin-bar single-author two-column right-sidebar">
side-page-copy template:
<body class="page page-id-2 page-template page-template-sidebar-copy-page-php logged-in admin-bar single-author singular two-column right-sidebar">

Related

Add comments to wordpress inspect element page

As the title says, I want to add some sort of signature with comments on my wordpress index file, thing is - there are 30 different index files and none of them seems to work
If I understand correctly, it'll just be a case of adding some HTML comments (not PHP comments as they won't show in the source code) in your theme files. Bear in mind that editing a theme won't work if someone else made it and releases updates to it as it'll overwrite your changes if you update it.
The best place to add in the comments is to either open the header.php file and place your HTML comments after the opening <body> tag. If your theme doesn't include a header file, you could always add your comments to the top of your themes index.php file instead.
Your theme should be located within /wp-content/themes/YOUR-THEME/.
Alternatively, you could also place HTML comments between the <head> tags of your theme so they show up a bit higher in the source code. To do this, it's probably best to use an action hook instead. Place this in your themes functions.php file:
add_action( 'wp_head', 'add_signature_to_theme', 1, 0 );
function add_signature_to_theme() {
?><!-- Welcome to my website. --><?php
}
The wp_head action hook documentation is useful to have as reference as well if you'd like a bit more information on what it is and what it does.

WordPress : Customize Genesis header

I am just diving into the Genesis Framework.
In a normal theme, if you want to edit the header, you'd open the header.php file.
But in genesis, the header file is not in the child theme. I have looked around and found a way to add custom header support, but i need some guidance.
The code below is to enable custom header support. I assume this goes into the functions.php file. But how to i actually add code here? What if i want to say pull in a custom field, or add a div to this section, or bring a slider in? How to i actually use this code to let me add html and php into the child theme header?
/** Add custom header support */
add_theme_support( 'genesis-custom-header',
array( 'width' => 960, 'height' => 100, 'textcolor' => '444',
'admin_header_callback' => 'minimum_admin_style' ) );
First you need to remove the header that is currently there. All of this goes into functions.php in your child theme
remove_action('genesis_header','genesis_do_header');
Then is it as simple as building a function to act as your new header.
function injectHeader() { ?>
<div id="title-area">
<h1>Title Here</h1>
<nav>Nav Here and so on</nav>
<p>You can add whatever you want</p>
</div>
<?php }
I normally try to use the same class and ID names so I can preserve some of the built in styles and save myself some work but that's up to you. All you have to do is add whatever you want in the function and call it back in like this,
add_action('genesis_header','injectHeader');
Hope that helps!
Just stumbled upon this post asking the same question. Great solution. An even easier way to customize certain parts of a genesis powered site is using the Genesis Simple Hooks plugin. Just do a search, it's awesome.

wordpress. error creating content for custom templates with twentytwelve theme

i'm using the twentytwelve theme and i have to write custom content into my example template.
I want to maintain my header content so the main structure is the following
header = id page, wrapper
ex.page = primary, content
footer = close wrapper, close id page
If i have understood correctly, if i want to insert content into the middle of my page i have to do it into my template page (that is a copy of the main page.php), that is in the middle between my header and my footer
For example i want to insert a div into which insert the loop of such category.
The problem is that it displays me nothing, like i've wrote nothing. I can only see the contents if i erase all the originary div, but it's not what i want to do, just because the only div is the page which is my container.
I can't catch what i have to do.
Can you tell me what i forgot to do?
Thanks,
Alex
page.php is a "master" document. header.php, footer.php and (if it exists) sidebar.php are all imported into page.php. Twenty Twelve also uses atomized content templates. You may need to add your div to content-page.php, which is also imported into page.php. content-page.php is used inside the wordpress loop, and encapsulates the code that pulls in the actual article elements from the wordpress database.
If you are trying to add straight HTML to the templates, ensure that you are not adding code between the php brackets:
<?php // don't add html here ?>
<div>do add html here</div>
Depending upon the type of wordpress page you are trying to display, you may need to consult the Wordpress Template hierarchy to determine the proper Wordpress naming convention for your template file (the copy of page.php).
Technically speaking, everything in content-page.php can be put into page.php replacing the get_template_part function. All the 'content' pages are totally not required and can be combined into one file if you want simplicity.
In my opinion, it's easier to start from scratch when learning Wordpress rather than try and re-work something. The default wordpress themes don't lend themselves to be beginner friendly.

admin template selection is missing on page creation in wordpress 3.2.x

I am using WordPress 3.2.1 ,
Page template selection drop down is missing on Pages (Add,Edit)
wp-admin > Pages >Add New > Page Attributes
I Edit the Template Page Default page as below code
/*
Template Name: New Template
*/
But still the template drop down no visible , my older version of WordPress it display by default.
Following is the screen shot for more idea
I solved this problem solved by adding the typical following code:
/*
Template Name: Custom
*/
Don't add any spaces after Name:
It'll work if you use template name: as well.
It might help someone: check if your index.php file is in place.
If it's not there, wordpress treats the template as corrupt and it doesn't display the template selection.
This should be simple to troubleshoot. The requirements for the page template to work are straight forward:
The template needs the page title in the top of the file like you've shown (the title needs to be wrapped in a PHP tag, you probably just didn't add it with your example bu I want to make sure you havne't overlooked it):
<?php
/*
Template Name: Custom
*/
?>
The second requirement is that the file is in the root of the theme folder.
With those two requirements in place, it should work. If it isn't working you nave a few possible issues. I list a few off the top of my head:
You might need to re-install WordPress in-case a file was corrupted
during your last update.
It's possible someone has altered the WP-Admin layout using users
roles.
That's all I can thing of at the moment, let me know how it turns out.
I had the same issue. It actually turned out to be a missing style.css file within the template directory in my case.
This happens because the get_post_templates() in class-wp-theme.php first checks for errors. If it finds any then it returns an empty array (no templates are displayed).
A side effect of this is that saving a page would clear the existing template and use the page.php instead.
So in short if the errors() method of your theme returns any errors then no templates dropdown.
hope that helps someone.
Same issued, I found out that in appearance panel in your WordPress dashboard the stylesheet is missing. You shouldn't rename the style.css in your theme folder.
Not sure if this will help anyone, but we solved the problem by disabling our theme and re-enabling it again. We had some other theme folders in the theme directory that we weren't using so we deleted those out as well. good luck, it's a really random problem to solve!
yeah!template dropdown not showing because you have no template So how to solve this::---
1 create template folder in theme
2 create a template in this folder
like:-
<?php /* Template Name: Home */ echo "template"; ?>
and check-in page dropdown will be there.

new content type, with completely blank(body of node only) output theme files

I have a content type that is only used for scripts on my drupal site that should return json data. So the issue then becomes that I can't have any of the theming elements of the site in the output.
So I know I need blank (only the output variable) tpl files for the following:
html.tpl.php
page.tpl.php
region.tpl.php
block.tpl.php
field.tpl.php (the manual says this isn't used but its the only way I could find to remove field divs around the body of my page)
So my question is, how can I create all of the content specific files for this content type? I know its easy to do a theme override in template.php BUT I can only get it to work for html.tpl,page.tpl and thats it. Drupal seems to ignore any content specific functions from region down to field.
I noticed you tagged this drupal-7, which I haven't tried yet. But, in Drupal 6 I would accomplish this by adding a new page template to $vars['template_files'][] in the page preprocess function of template.php. Example:
$node_type = $vars['node']->type;
if ($node_type == '{your content type name here}') {
$vars['template_files'][] = "page-" . $node_type;
}
If your content type was called 'scripts', then Drupal will look for a page called page-scripts.tpl.php, which will contain only one line:
<?php print $content; ?>

Resources