After updating (or maybe not) but some time before, when I'm going to category list page mysite.com/?cat=10 I'm getting not category.php template - it opens single.php Why?
I was trying to make category-10.php (just for test) but still coming to single.php . Where I should look about my problem? The problem was with my ajax plugin his code is :
<?php
/**
* Plugin Name: Ajax content loader
* Description: Load content througt ajax.
* Version: 0.1
*
*/
/**
* Initialization. Add our script if needed on this page.
*/
function ajax_content_init() {
global $wp_query;
// Add code to index pages.
if( !is_singular() ) {
// Queue JS
wp_enqueue_script(
'load-posts',
plugin_dir_url( __FILE__ ) . 'js/load-posts.js',
array('jquery'),
'1.0',
true
);
$wp_query->is_single = true;
}
}
add_action('template_redirect', 'ajax_content_init');
?>
Any ideas what is wrong here? It is for mobile version, how to activate him only for mobile? not for desktop?
Download the WordPress Debug Bar Plugin . It will add a button to your wp-admin bar that says "Debug". When pressed, this button will show you the debug panel. Find the tab in this debug panel that says "WP Query", and it should show you query vars and the template file that are being used.
This should help you figure out what query vars are being registered, and which template file is really loaded.
You should read wordpress codex for template_redirect before trying to experiment things.
This action hook executes just before WordPress determines which template page to load.
What are you actually trying is:
if( !is_singular() ) {
If page is not a singular, means is not a template page.php
or single.php
it should execute the code.
So when you were at category.php
it executed the code and sets the global $wp_query
layer objects property single
to true
. So whatever template you were viewing at that time it will set that page as single
.
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.