Wordpress theme name inside theme php files, what is the purpose of this? - wordpress

I've been building basic themes now for nearly a year, and I'm trying to clean up my style as much as possible. But I don't know where to look to find out what this does...
In the kubrick theme php files, for example you get a php tag like this...
<?php the_content('<p class="serif">' . __('Read the rest of this entry »', 'kubrick') . '</p>'); ?>
You see the theme name 'kubrick' weaved in. What is the purpose of this?
You see it in all themes, twentyten, twentyeleven, etc.. but I never notice a difference if I leave it the same. What benefits does this have if I change it to my current theme name?
Can anyone enlighten me? or point me in the right direction?
Thanks
Josh

This is the 'theme text domain' and is typically used for localization. You can find out more by reading the gettext filter reference. One note is that the text domain is not required to be the same as your theme name. You can make it whatever you want as long as you are consistent with what you load using load_theme_textdomain. It's just convention to make it the same as your theme name. Finally, as to why you should bother including a domain here is a quote from an article called How to localize WordPress themes and plugins with GetText:
Have you noticed the 2nd argument in the GetText calls? It’s an
optional argument that tells GetText what the scope (domain) of the
texts is. If supplied, this GetText will return the translations only
from the dictionary that you supply with that domain name. Although
optional, specifying the translation domain is highly recommended.
Without it, GetText might return a different translation, if the same
string also appears in a different plugin, or in WordPress.

Related

Wordpress child theme internationalization

I have followed the steps about "Internationalisation" on the wordpress codex page http://codex.wordpress.org/Child_Themes
To internationalize a child theme follow these steps:
Add a languages directory.
Something like my-theme/languages/.
Add language files.
Your filenames have to be he_IL.po & he_IL.mo (depending on your language), unlike plugin files which are domain-he_IL.xx.
Load a textdomain.
Use load_child_theme_textdomain() in functions.php during the after_setup_theme action.
The text domain defined in load_child_theme_textdomain() should be used to translate all strings in the child theme.
Use GetText functions to add i18n support for your strings.
What about the last step about using getText functions.
Please give me an example about using the getText function and where should I put these strings?
GetText functions are basically
__('mystring' , 'mytextdomain') and _e('mystring', 'mytextdomain') which is a wrapper for
echo __('mystring', 'mytextdomain')
All strings in your theme should be wrapped this way.
This is all detailed in http://codex.wordpress.org/I18n_for_WordPress_Developers which is a link on the page for creating Child Themes
You should always follow these kind on links in the codex, they give useful information ^^

Drupal6 template file not recognised

I've create a nodequeue and set the "Description / Tag" in the Defaults section to "Entertainment Highlights" and when I click to view Theme: Information it has a template suggest for style output of
views-view-list.tpl.php
views-view-list--nodequeue-91.tpl.php
views-view-list--entertainment-highlights.tpl.php
views-view-list--default.tpl.php
views-view-list--nodequeue-91--default.tpl.php
This looked great because I was hoping to make a template in my theme for views-view-list--entertainment-highlights.tpl.php which wouldn't tie it to a particular nodequeue (building on dev and when I come to put live the nodequeue ID will likely have changed) however when I create the file on the file system and click rescan it doesn't highlight that template name suggesting drupal is not finding it.
If I create a file called views-view-list--nodequeue-91.tpl.php then this works fine and if I change the "Description / Tag" to simply "Entertainment" and create a views-view-list--entertainment.tpl.php file then this is also picked up by drupal so the issue looks like it's tied to spaced in the "Description / Tag" name
Does anyone have any ideas what I need to update to get the template to work. I realise it's likely to be a core tweak but it would be really helpful if it could handle cases like these.
I found this was not related directly to Drupal6 but instead was related to the OpenPublish variation we are using.
Turns out there is a function called _views_theme_functions() in /sites/modules/views/themes/theme.inc (not to be confused with /includes/theme.inc) which is using the following to determine the name of the theme templates
$themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '-', strtolower($view->tag));
However if you examine $themes you can see all the non a-z0-9 characters have been replaced with underscores rather than dashes so needed to amend it to
$themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($view->tag));
I realise this is a core amendment and ideally I wouldn't make this change here.

How do I target a SPECIFIC template with is_page_template() in Wordpress 3+

I'm running Wordpress 3.2 and I need a conditional to test for a certain template. My template is a file called special_offer.php. The name of the template is "Special Offer". I've tried both of the following:
is_page_template('special_offer.php');
is_page_template('Special Offer');
Neither of these work! The documentation clearly says that the parameter should be a string with the name of the file so I'm not sure what's wrong. I know the function is at least partially working because if I don't include a parameter, it returns true for any pages using templates (as expected).
AHA!
I solved this by adding wp_reset_query() just before the conditional.
I had already read warnings about many WP conditionals not working inside the loop. However, my conditional is NOT inside a loop. Turns out, it won't work even AFTER the loop, which is where mine was. So you you need to reset the query before you call it.
It's worth double checking which file is being used according to the WordPress template hierarchy [image].
Try adding this magic constant to the template file you think is being called:
<?php echo(__FILE__); ?>
If you don't see a path and filename a different file is being used (refer to the template hierarchy diagram in the link above) or check which templates are available:
<?php print_r( get_page_templates() ); ?>
(^ looks like this has to be called from the admin interface e.g. in a plugin)
Also, the documentation seems to state that is_page_template() won't work in the Loop without calling another function first.

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.

Can I use a wordpress theme in new php pages?

I'm putting together a web site that needed to include some signup and blogging capability. Wordpress seems to be a perfect fit for that portion of the app, so I've started experimenting with it. I see plenty of tutorials on creating custom themes so I don't expect that to be a problem.
What I'm not able to figure out is what to do with the rest of my site. I will have other non-blogging related php pages that will access a database, etc. I see that wordpress has a capability for generic pages of static content, but these would need to be coded PHP pages. I just can't find a way of having the wordpress theme apply to other php pages outside of wordpress. I was hoping of just doing something like
wp_header();
blah blah
wp_sidebar();
blah blah
wp_footer();
but I'm not really seeing any examples or documentation on how this might be done. Am I missing a key piece of documentation?
EDIT: The answer is to essentially copy and paste a file from the theme, with one crucial addition:
require( dirname(__FILE__) . 'path_to_wp_root/wp-load.php');
That sets up the wordpress environment and allows me to call get_header(), get_sidebar(), get_footer(), etc.
Generally, "yes".
A well-designed WordPress theme uses mostly CSS/Stylesheets for display, and you are correct in your assumptions: Look through the "Codex" about Theme Design / Template Design (http://codex.wordpress.org/Stepping_Into_Templates).
Essentially you could base your design on some of the current theme files, but leave out "the loop".
I think what you really want to do is include wp-load.php at the top of your php file. This will give you access to all the wordpress functions (wp-header(), wp-footer(), etc).
wordpress has pages in it. each page can have its own content and its own template and still be part of the whole wordpress site. i mean it will share the header and the footer if you want and will share the css and javascript that you include in both.
for more information on pages and pages templates
What you should do is develop your other non-blogging related php pages as a wordpress plugin. There are plenty of references online on how to do this, for example:
http://www.tutorialized.com/view/tutorial/Creating-a-Custom-Wordpress-Plugin-from-Scratch/41834
Another option is to use Wordpress as the CMS for all content on your site. This is increasingly becoming popular, as Wordpress is quite good at non-blog-things these days.
define('STYLESHEETPATH', '');
define('TEMPLATEPATH', '');
$base = substr(__DIR__, 0,strrpos(__DIR__, '/[name of the dir where u store the php files]'));
require_once($base."/wp-load.php");
require_once($base."/wp-includes/pluggable.php");
easy to use wordpress function outside

Resources