我试图通过ajax加载nextgen Gallery,但是我得到了这个错误
我试了很多方法,现在离我更近了
function noix_galeria_click() {
// check nonce
$nonce = $_POST['nextNonce'];
if ( ! wp_verify_nonce( $nonce, 'myajax-next-nonce' ) )
die ( 'Busted!');
$cobertura = get_post_meta($_POST['postId'], 'id_da_galeria', true);;
echo nggShowGallery($galeria);
exit;
}这将作为响应返回
<h1>Exception thrown</h1><p>No utilities registered for `I_Display_Type_Controller`</p>ajax起作用了,用wp_queries试过了,还有一堆东西,都起作用了,除了nextgen画廊相关的东西
我认为这是一段报告错误的代码
function _retrieve_utility_class($interface, $context='all')
{
$class = FALSE;
if (!$context) $context = 'all';
if (isset($this->_utilities[$interface])) {
if (isset($this->_utilities[$interface][$context])) {
$class = $this->_utilities[$interface][$context];
}
// No utility defined for the specified interface
else {
if ($context == 'all') $context = 'default';
$class = $this->_retrieve_utility_class($interface, FALSE);
if (!$class)
throw new Exception("No utility registered for `{$interface}` with the `{$context}` context.");
}
}
else throw new Exception("No utilities registered for `{$interface}`");
return $class;
}我还能尝试什么呢?
编辑--我试图查找这些方法调用,并将此文件更改为wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_gallery_display/module.nextgen_gallery_display.php,查找!is_admin(),更改为真(用于测试),错误更改为:
<h1>Default Gallery Type Template</h1>
<p>
This is the default gallery type template, located in:<br/>
<b>/home/ian/Sites/portalsabores/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_gallery_display/templates/index.php</b>.
</p>
<p>我尝试指定模板:echo nggShowGallery($galeria, 'coberturas', 8);,但没有任何更改
这似乎与wordpress ajax api进行管理调用https://wordpress.stackexchange.com/questions/53309/why-might-a-plugins-do-shortcode-not-work-in-an-ajax-request有关
有办法改变这一点吗?
发布于 2015-05-29 05:42:12
我使用SMK theme view将ajax返回更改为模板部件,ajax操作变为:
function noix_galeria_click() {
// check nonce
$nonce = $_POST['nextNonce'];
if ( ! wp_verify_nonce( $nonce, 'myajax-next-nonce' ) )
die ( 'Busted!');
$cobertura = get_post_meta($_POST['postId'], 'id_da_galeria', true);
ob_start();
?>
<?php smk_get_template_part('parts/coberturas/galeria-principal.php', array(
'galeria' => $cobertura,
'post_id' => $_POST['postId']
)); ?>
<?php
$output = ob_get_contents();
ob_end_clean();
echo $output;
die();
}使用smk,您可以通过get_template_part函数发送变量
在galeria-principal.php上,我有
<?php
global $nggdb;
$gall_ids = $nggdb->get_ids_from_gallery($this->galeria); // smk allow you to return the variables as properties of $this
$images = $nggdb->find_images_in_list($gall_ids); // see these methods at
// wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/lib/ngg-db.php
// then build the template
$evento = get_post($this->post_id);
?>
<...>
<?php foreach ($images as $image): ?>
<?php
// I build this path because imageURL was empty, not sure why
$file_path = get_home_url() .$image->_ngiw->_cache['path'] . '/' . $image->_ngiw->_cache['filename'];
$file_desc = $image->_ngiw->_cache['description'];
?>
<li>
<img src="<?php echo $file_path ?>" alt="<?php echo $file_desc ?>">
</li>
<?php endforeach ?>
<...>这将在ajax中正常工作
https://stackoverflow.com/questions/30511142
复制相似问题