Why templates directory?


Author Message
ChrisManDenver

Posted: 9/8/2010
Quote message 

Why is there a "templates" directory under the theme directory? <br />
I want to alter my page.php but only in a child theme to the main theme. I have:<br />
&nbsp;&nbsp;wp-content/themes/[theme-name]/page.php<br />
&nbsp;&nbsp;wp-content/themes/[theme-name]/templates/page.php<br />
Why does it take two page.php's?<br />
<br />
When I try to override the page.php in my child theme, it is ignored.<br />
I have:<br />
&nbsp;&nbsp;wp-content/themes/[theme-name-child]/page.php (copy of the original)<br />
&nbsp;&nbsp;wp-content/themes/[theme-name-child]/templates/page.php (which has my changes)<br />
My changes are ignored.<br />

I am using a different child style.css, header.php and functions.php which are working fine.<br />
Changing the one page.php works fine in my child to twentyten.<br />
How do I make the child templates work with Artisteer ?<br />
 
ChrisManDenver

Posted: 9/9/2010
Quote message 

Sorry. I entered plain text and previewed - a mess run together. I put in HTML to format and preview was great. I submitted and you see what I got.

Plesae try to look beyound the formatting. I could really use an answer.
 
Abland

Posted: 9/9/2010
Quote message 

Hi, ChrisManDenver,

This is a theory only, but try this:

Create in your child theme a directory "core", and inside that create "parser.php" and copy your parent theme's parser.php file contents into that new file:

<?php


function parse_template($template_name, $variables = array())
{
extract($variables, EXTR_SKIP);
ob_start();
include (TEMPLATEPATH . '/templates/'.$template_name.'.php');
return ob_get_clean();
}


I don't have answers to your other questions but if you post the results from trying this then I might.
 
Adeptris

Posted: 9/9/2010
Quote message 

Hi Guys,
Not sure what this is but the way that WordPress and child themes looks for files is like this:

TEMPLATEPATH = Parent Directory
get_bloginfo('template_directory') = Parent Directory

STYLESHEETPATH = Child Theme Directory
get_bloginfo('stylesheet_directory') = Child Theme Directory

When WordPress looks for a file it will look first in the child theme directory then in the parent theme.

Artisteer have bypassed this with the function, and I cannot see a way to overide this function as you need a fall through position, I would contact support and ask them!

You could create the function in a functions.php in the child theme, rename the function 'child_' and call this new function when you need to?


<?php function child_parse_template($template_name, $variables = array())
{
extract($variables, EXTR_SKIP);
ob_start();
include (STYLESHEETPATH . '/templates/'.$template_name.'.php'); return ob_get_clean();
}


HTH

David :-(
 
ChrisManDenver

Posted: 9/9/2010
Quote message 

Abland,

I tried your suggestion and got the exact same results - it ignores changes in my child theme in the templates directory.

Why is there a new templates directory? Why are there two page.php's; one in theme directory and one in theme/templates directory?

Thanks for you assistance,
Chris
 
ChrisManDenver

Posted: 9/9/2010
Quote message 

Adeptis,

I thought it would be that Artisteer had broken how WordPress expected to function and your comment confirm that. That is why I wanted ask in this forum.

I think I understand what you have proposed, but I am working with the generated theme that needs in all cases to check the child then check the parent. Not just new code I would generate.

I will contact support on this issue. But, if there are other ideas?

Thanks for your assistance too,
Chris
 
Abland

Posted: 9/9/2010
Quote message 

Hi, Chris and David,

I like a challenge :-D

Okay, here it is:

*** This is for Artisteer 2.5.0.31067 - Aug 30 release

Create in wp-content your new theme folder. Theme's can have any variety of names, but for simplicity let's call the child theme "child theme" and the parent theme "parent theme".

We now have:
"wp-content/parent_theme" and
"wp-content/child_theme"

In the child theme create "style.css" and paste in the following:

/*

Theme Name: child theme
Description: Child theme for the Parent theme
Author: Abland
Template: parent_theme
*/

@import url("../parent_theme/style.css");


In the child theme create "page.php" and copy in the contents of "parent_theme/page.php".

In the child theme create a folder "templates" and in that folder create "page.php" and copy in the contents of "parent_theme/templates/page.php".

In the child theme create "functions.php" and paste in the following:

<?php


if (!function_exists('art_parse_template')) {

function art_parse_template($template_name, $variables = array(), $ext = null)
{
if ($ext === null ){
$ext = art_option('theme.template_ext');
}
$path = STYLESHEETPATH . '/templates/'.$template_name.'.'.$ext;
if (!is_readable($path)) {
$path = TEMPLATEPATH .'/templates/'.$template_name.'.'.$ext;
}
if ($ext == 'php'){
extract($variables, EXTR_SKIP);
ob_start();
include ($path);
return ob_get_clean();
} else {
$content = file_get_contents($path);
return art_parse($content, $variables);

}
}
}


The only change we're going to do to the parent file is in "parent_theme/core/parser.php". This change is something Artisteer can add to the next release to support child themes, because if there are no child themes the parser function carries on as normal.

We are going to wrap the first function in the parser.php in:

if (!function_exists('art_parse_template')) {


}


as follows:

<?php

if (!function_exists('art_parse_template')) {
function art_parse_template($template_name, $variables = array(), $ext = null)
{
if ($ext === null ){
$ext = art_option('theme.template_ext');
}
$path = TEMPLATEPATH . '/templates/'.$template_name.'.'.$ext;
if (!is_readable($path)) return '';
if ($ext == 'php'){
extract($variables, EXTR_SKIP);
ob_start();
include ($path);
return ob_get_clean();
} else {
$content = file_get_contents($path);
return art_parse($content, $variables);
}

}
}


When the child theme is activated, make changes to the child theme's "templates/page.php" and your site will reflect those changes. Templates can now be added to the child theme in the same manner as the parent without changing the parent's files.
 
ChrisManDenver

Posted: 9/9/2010
Quote message 

I followed it all but didn't fully understand the child function code override (or is it overload) - I was accepting that on faith for now.

I have also run into the issue that to override an existing function from the child, you must still change the parent to wrap it in "function_exists". It kinda defeats the purpose of allowing the child to contain all changes. I've already sucked it up and done this in another case.

The issue I run into is that my parser.php does not look like your parser.php. My parent/core/parser.php code is:
<?php

function parse_template($template_name, $variables = array())
{
extract($variables, EXTR_SKIP);
ob_start();
include (TEMPLATEPATH . '/templates/'.$template_name.'.php');
return ob_get_clean();
}


not the expected art_parse_template.
 
ChrisManDenver

Posted: 9/9/2010
Quote message 

Oops - Is it that I am still running Artisteer.2.5.0.29918?
 
ChrisManDenver

Posted: 9/9/2010
Quote message 

That was the reason. I updated my Artisteer version, resaved my theme and copied it over. I had to re-apply all of my changes in my child theme since the files they were based on changed. Good lesson to learn.

You're my hero. Worked like a charm! Why doesn't Artisteer hire you - please.

All of this was simply to change the text of the footnote, i.e. "Powered by...". But now, it will accept ANY child theme template override.

I will update my outstanding question to Support and see what they do with it.

THANKS
 
ChrisManDenver

Posted: 9/10/2010
Quote message 

Support response as follows:

--------------------------------------------------
Our goal was to extract all the HTML into files separate from PHP so that it is easier to modify just the web design without changing PHP code.
However...
we realize that our new approach may make it difficult for other people to utilize common WP customization solutions found on WP forums and generally via Google.

Therefore we have assigned our WP developers to reassamble HTML+PHP back to the previous file structure that's so familiar to WP developers.
Unfortunately such file structure may make it impossible to implement some new features that we were planning to add to our WP templates.
But anyway, our developers will try their best to keep Artisteer templates as good, well-structured and flexible as possible.

We will inform you and other customers about the progress via our News page.
--------------------------------------------------


I have an oustanding question as to whether customers should revert to 2.4 and wait for a new release.
 
Adeptris

Posted: 9/10/2010
Quote message 

If they are good to thier word, I shall be returning to the Artisteer Community!

David :-D
 
ChrisManDenver

Posted: 9/10/2010
Quote message 

Latest Support response:

--------------------------------------------------
We plan to update Artisteer 2.5 in the future.
Unfortunately I can't provide you with exactly date yet.

>Are you saying any work done in Artisteer 2.5 will quite likely be undone in the next release? Would it be better for us to go back to 2.4 and wait for the next release?<
No.
We plan to update "old" WP themes to support all new features and keep the previous file structure.
All other functionality should be the same.

Therefore you can stay with the current file structure or use the future update.
--------------------------------------------------

 
ChrisManDenver

Posted: 9/21/2010
Quote message 

This thread has been quoted in several other places so I will try to keep it up-to-date with comments from support.

I consider this an Artisteer 2.5 bug since a child template cannot override a parent template without Abland's fix. I asked support how they are reporting bugs to the user base - "In the meantime, how are you notifying customers that this bug (or any reported bug) exists in '2.5.0.31067'? "

Latest Support response:

--------------------------------------------------
We actually do not consider this a bug, but rather a difference in Artisteer and the default Twenty Ten template structure.

As Helga mentioned above, our developers deliberately changed the structure of our themes and separated HTML/presentation files from PHP/logic files.

We thought that many developers or advanced users would quickly understand a few benefits of this approach because this is how most web applications evolve anyway - by separating coding from HTML.
Those are great development and templating standards that actually allow updating web templates in any CMS without dealing with PHP files, permissions, and having access to the server.
We actually need this ourselves for our own installation of WPMU that we will be launching soon.
We also see that some professional WordPress themes make quite serious changes to the WP theme structure to support more professional needs.

Anyway, we've already realized that the new approach is a challenge, and the value of our changes cannot be appreciated by people who search for solutions on WP forums or via the Internet.

That's why we've made a decision to revert back to the standard theme structure.
Our developers are currently working on this task.
We will release a new Artisteer 2.5 update when they are finished.

In the meantime (if the latest WordPress 3.0 features are not important to you) you can downgrade to Artisteer 2.4 and wait for the next 2.5 release.

Or you can continue using 2.5 theme with the Abland's solution implemented.

Unfortunately, this or similar 2.5-specific solutions may not work in the future after the structure of templates is changed.
We apologize for the inconvenience.

I also need to say that most Artisteer customers never modify the generated code and didn't even notice that the structure of themes was changed.
We've released Artisteer 2.5 more than a month ago and didn't see much feedback except general issues or questions.
That's why for now it does not seem necessary to provide such technical information or post any technical solutions on our website.
--------------------------------------------------
 
Adeptris

Posted: 9/21/2010
Quote message 

Looks like we are getting a proper forum!

Quote :
We actually need this ourselves for our own installation of WPMU that we will be launching soon.


Also nice to see that Artisteer are on the case, and I agree that most users would not even know about the changes, as they are happy with the default themes.

Quote :
We also see that some professional WordPress themes make quite serious changes to the WP theme structure to support more professional needs.


The difference between 'twenty ten' the new Artisteer structure is two widget areas, the Artisteer Vmenu, and the ini file which has caused some issues, twenty ten has a smaller file footprint.

The frameworks and professional themes come packed with a large number of features out the box, if 2.5 had come with these we would not be having this conversation and would be singing the praises.

David :-/
 
Adeptris

Posted: 9/21/2010
Quote message 

Quote :
Or you can continue using 2.5 theme with the Abland's solution implemented.


Hope the check is in the post o Abland for the IP royalties?

David :-D


 
Brett Bumeter

Posted: 9/21/2010
Quote message 

As I understand it the new website for Artisteer or at least the community will be powered by WordPress, which should enable a better forum through multi user. Past conversations I've had indicated that this reversion/bug fix/what ever you want to call it, has been in the works for almost 2 weeks now, so hoping to see it roll out sooner rather than later myself. :)

In the meantime, I'm running 2.4 with Toemon's 3.0 patch myself. (notes here http://softduit.com/how-to-upgrade-theme-wordpress-3/ )

Is Abland = Toemon or is that something else?