Changed template name and now wp_list_comments() is not working - wordpress

I had to change the template folder name because it had a space it in. That messed with my HTML validity.
So 'Panda Productions' -->became--> 'PandaProductions'
Now wp_list_comments(); doesn't work. Comments aren't showing up.
When I changed the name back, it worked again.

Basically, in single.php (or in other pages optionally) WordPress adds comment template depending on function call of comments_template(), which means the comment template is a separate file and by calling this function (mentioned above) we add comment template in files/pages like single.php, this functions accepts optional parameters and one parameter is being used as a filename to load the template file, if a filename is supplied with the function then it loads that file as the comment template, otherwise it looks for /comments.php file in the same folder by default. You can see the source of this function here.
So, I think, the problem is that, this function (comments_template()) is called in your single.php with the folder path/name and that's why it's not being loaded after you change the folder name. If you search for this function call then you may find the path and filename that used in your theme and you can modify those as well.

Related

How is functions.php loaded in Wordpress?

I am starting to study Wordpress a bit deeper and i d like to know which way functions.php file is loaded so that every function is available everywhere in the theme files.
Or at least if you suggest me some source where to find this information.
Thank you
A function.php file:
Executes only when in the currently activated theme's directory.
Applies only to that theme. If the Theme is changed, the functionality is unused.
Requires no unique Header text.
Is stored with each Theme in the Theme's subdirectory in wp-content/themes.
Each theme has its own functions file, but only the functions.php in the active Theme affects how your site publicly displays. If your theme already has a functions file, you can add code to it. If not, you can create a plain-text file named functions.php to add to your theme's directory.
Source # https://codex.wordpress.org/Functions_File_Explained.
In short, the function.php file is a function wrapper. Each function is hooked to a specific action hook. These actions are called when a user opens a page (Server request).
You can get a better understanding of how action hook work by looking at the Plugin API/Action Reference which represent a typical hook firing sequence.

add_filter hook not working in plugin's php file

I am developing a plugin and it works fine when I call my code from my plugin's main php file but I want to run only once My external file is called in the plugin. I mean I want to place my function inside includes folder and in a file living there. like plugin folder/includes/file.php ... here is my code
add_filter('wp_nav_menu_items',',my_custom_function');
function my_custom_function ($nav){
return $nav."<li class='menu-header-search'><a href='#'>Icon</a></li>";
}
Kindly let me know how can I make it work, it works in side plugin's main php file but does not work from other php files inside plugin includes folder.
It should work if you include your file from the plugins main file, just make sure it is included correctly.
include plugin_dir_path( __FILE__ ) . 'includes/file.php;
This would include a file in an includes folder in your custom plugin folder, and would include an file named: "file.php". If you want to know if its been loaded correctly, just add an die() statement in the included file:
die('my include file has been loaded correctly');
Just remove the die() statement after you have an confirmation that its working :) Lastly you need to copy your callback function code and paste it in your included file. If your hook still does not work, then it might be something wrong with your callback function.
The documentation for the filter hook you are using:
https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/

separate js file for front page

I am working on a drupal 7 site and am very new to this. I need to create a totally separate home page from the rest of the site. I notice the head is built in the html.tpl.php file where all the scripts are loaded. I would rather not load scripts to the rest of the site that will only be used on the front page. Also I have found that drupal adds some code to the end of my script rendering it useless.
/js/image_scale.js?lwhgie"
What is going on here and how do get better control of this?
Thanks
Just to add a couple of points:
If you want to aggregate your homepage JS (which you may or may not) then you shouldn't add the stylesheets manually to the template file. You can add them in hook_preprocess_page(), something like this:
/**
* Implements hook_preprocess_page().
*/
function MYMODULE_preprocess_page(&$vars) {
if ($vars['is_front']) {
$path = drupal_get_path('module', 'MYMODULE');
drupal_add_js($path . '/MYMODULE1.js');
drupal_add_js($path . '/MYMODULE2.js');
$vars['scripts'] = drupal_get_js();
}
}
Also I have found that drupal adds some code to the end of my script rendering it useless.
/js/image_scale.js?lwhgie"
That shouldn't render your script useless. From the comments in drupal_get_js():
A dummy query-string is added to filenames, to gain control over
browser-caching. The string changes on every update or full cache
flush, forcing browsers to load a new copy of the files, as the
URL changed. Files that should not be cached (see drupal_add_js())
get time() as query-string instead, to enforce reload on every
page request.
you could create a new template called page--front.tpl.php in your theme folder and this will be your template for the homepage. Now you can add/remove any html markup you want. for more info take a look here: http://drupal.org/node/1089656 . Also, you could "tell" drupal to use your custom template file using hook_preprocess_page() in template.php file in your theme folder. See the comments on the link I posted earlier

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.

Drupal: Translation template extractor works but the string cannot be found

I'm using Translation template extractor to extract transable strings I've added to my page.tpl.php page in my zen theme files.
I've correctly exporeted zen.pot file and overwritten the previous one. The string 'random text' contained in the t('random text') function in the template is correctly added to the file.
I've refreshed cache, refreshed the tab and run cron again.
However when I search for it in the translation interface I cannot find it and therefore I cannot translate it.
thanks
The solution was to switch the language of the page containing the string at least once to save the string.
Export a .po-file, edit it with (e.g with Poedit) save the file and import it into Drupal.

Resources