我在自定义wordpress主题上使用qTranslate,我有一个jQuery ajax调用,加载正确的'admin-ajax.php /?lang ='值并调用functions.php上的构造
当您调用Ajax时(在new.whatonline.org上检查,在页脚前加载'加载更多'按钮,如果您使用英文版,则会翻译新的大拇指,但不会翻译类别)。< / p>
我尝试了不同的解决方案(_e(),之前选择语言等)但是我没有到达修复它,我调用函数的代码是
foreach((get_the_category()) as $category) {
if (!($category->cat_ID==894) && !($category->cat_ID==895) && !($category->cat_ID==902) && !($category->cat_ID==903) && !($category->category_parent==902)){
echo '<a href="';
echo get_category_link( $category->term_id );
echo '" >';
echo $category->cat_name;
echo '</a>, ';
}
}
它在页面加载时起作用,但在AJAX调用时不起作用。我还打印了$ category值,我看到所有的数组,但没有翻译的值,在其他内容如'the_content'我可以看到&lt; - :en - &gt;&lt; - :es- - &GT;如果我输出原始值但不输出类别(我没有在mySQL数据库中找到结构)所以我猜问题来自第一个插件函数,不是吗?
PS。最后一个类别是翻译的,因为它不是真正的类别,我使用_e(XXXX,'qtranslate')hack
感谢。
的更新
这是来自jQuery的ajax调用...
jQuery.ajax({
type: 'POST',
cache: false,
url: idioma,
data: {"action": "listposts", cat : categories, neworder : order, offset : postoffset}
})
.success(function(data) {
//Añadimos los nuevos posts a la cola y borramos los anteriores
$(".results").append(data).show();
datosact.remove();
postoffset = postoffset + 20;
//Vovlemos a poner los textos bien y devolvemos el fondo de carga a su estado inicial
$('#loadmore').children('a').text( morearticles );
$('#loading').removeClass('active');
return false;
});
和构造的php函数
function listposts() {
global $post;
$output = '';
$cat_id = $_POST[ 'cat' ];
$orderby = $_POST[ 'neworder' ];
$offset = $_POST[ 'offset' ];
$metakey ='';
if ($orderby == "by_views"){
$orderby = "meta_value_num";
$metakey = 'views';
}
$args = array (
'category__and' => $cat_id,
'meta_key' => $metakey,
'post__not_in' => get_option( 'sticky_posts' ),
'orderby' => $orderby,
'post_status' => 'publish',
'posts_per_page' => 20+$offset
);
$listposts = new WP_Query($args);
while($listposts->have_posts()) : $listposts->the_post();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'listado' );
$str = get_post_meta($post->ID, 'subcat', true);
$vistas = get_post_meta( get_the_ID(), 'views', true );
echo "<article class='posts'><a href='";
echo the_permalink();
echo "'><img src='";
echo $thumb['0'];
echo "' alt='";
the_title();
echo "'><div class='hover_content'><ul><li><span class='icon-eye'><br>";
echo $vistas;
echo "</span></li><li><span class='icon-share'><br>";
echo render_socialcounter();
echo "</span></li></ul></div></a><a href=";
echo the_permalink();
echo "'><h1>";
the_title();
echo "</h1></a><div class='posts-tags'>";
//This function do the loop that I posted before
what_categories();
echo "<a href='tag/";
what_tags();
echo "'>";
echo _e($str, 'qtranslate');
echo "</a></div><div class='posts-extract'>";
echo $content = "<p>".new_excerpt(180)."...</p>";
echo "</div></article>";
endwhile;
die($output);
}
add_action('wp_ajax_listposts', 'listposts');
add_action('wp_ajax_nopriv_listposts', 'listposts'); // not really needed
答案 0 :(得分:0)
根据您的代码,您的代码中缺少两件事
这些是通过ajax发送以使用Wordpress AJAX的必需值。
jQuery.ajax({
type: 'POST',
cache: false,
action: 'listposts',
url: <?php echo admin_url( 'admin-ajax.php' ) ?>,
data: {"action": "listposts", cat : categories, neworder : order, offset : postoffset}
})
.success(function(data) {
//Añadimos los nuevos posts a la cola y borramos los anteriores
$(".results").append(data).show();
datosact.remove();
postoffset = postoffset + 20;
//Vovlemos a poner los textos bien y devolvemos el fondo de carga a su estado inicial
$('#loadmore').children('a').text( morearticles );
$('#loading').removeClass('active');
return false;
});
您无法在没有操作参数的情况下调用ajax,因为这样就无法唯一地识别ajax请求。