Php 类别不使用qtranslate+;对wordpress的ajax调用

Php 类别不使用qtranslate+;对wordpress的ajax调用,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我在自定义wordpress主题上使用qTranslate,我有一个jQuery ajax调用,它加载正确的“admin ajax.php/?lang=”值并调用functions.php上的构造 当您调用Ajax时(在new.whatonline.org上查看,页脚前的“加载更多”按钮,如果您使用的是英语版本,您将翻译新的拇指,但不会翻译类别) 我尝试了不同的解决方案(_e(),选择之前的语言,等等),但我没有找到解决方案,我为函数调用的代码是 foreach((get_the_categor

我在自定义wordpress主题上使用qTranslate,我有一个jQuery ajax调用,它加载正确的“admin ajax.php/?lang=”值并调用functions.php上的构造

当您调用Ajax时(在new.whatonline.org上查看,页脚前的“加载更多”按钮,如果您使用的是英语版本,您将翻译新的拇指,但不会翻译类别)

我尝试了不同的解决方案(_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>, ';
    }
}
以及用于构造的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
函数listposts(){
全球$员额;
$output='';
$cat_id=$_POST['cat'];
$orderby=$_POST['neworder'];
$offset=$_POST['offset'];
$metakey='';
如果($orderby==“by_视图”){
$orderby=“meta\u value\u num”;
$metakey='views';
}   
$args=数组(
“类别”和“=>类别id”,
“meta_key”=>metakey$,
'post_unot_in'=>get_选项('sticky_posts'),
'orderby'=>$orderby,
“发布状态”=>“发布”,
“每页帖子数”=>20+$offset
);
$listposts=新的WP_查询($args);
而($listposts->have_posts()):$listposts->the_post();
$thumb=wp\u get\u attachment\u image\u src(get\u post\u缩略图\u id($post->id),'listado');
$str=get\u post\u meta($post->ID,'subcat',true);
$vistas=get_post_meta(get_ID(),'views',true);
回声“;
//这个函数执行我之前发布的循环
什么类别;
回声“;
echo$content=“”。新摘录(180)。“…

”; 回声“; 结束时; 模具(产量); } 添加动作(“wp_ajax_listposts”,“listposts”); 添加动作('wp_ajax_nopriv_listposts','listposts');//不需要
根据您的代码,您的代码中缺少两件事

  • AJAX url
  • 行动
  • 这些是通过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;
    });
    
    jQuery.ajax({
    键入:“POST”,
    cache:false,
    行动:'listposts',
    网址:,
    数据:{“操作”:“listposts”,类别:类别,新订单:订单,偏移量:postoffset}
    })
    .success(函数(数据){
    //阿尼亚迪莫斯·洛斯·努埃沃斯发布了一份可口可乐和博拉莫斯的前情
    $(“.results”).append(data.show();
    datosact.remove();
    后偏移=后偏移+20;
    //请注意,这是一种特殊的交通工具
    $('loadmore').children('a').text(morearticles);
    $('加载').removeClass('活动');
    返回false;
    });
    
    没有action参数就不能调用ajax,因为这样就无法唯一地标识ajax请求

    参考


    您是否正在发送带有AJAX请求的操作?请添加您的ajax代码及其php处理程序。您好@abhineetwerma,刚刚将此信息添加到帖子中。您是否找到阻止qtranslate获取
    $cat=
    arg的原因?我对帖子列表WP查询也有类似的问题:
    我无法创建一个由
    $cat
    标记分隔的循环,其他$args正在工作(例如:
    $p=66
    )Hi@maioman,在我的例子中,最后是url调用的问题,带有'idioma=";' 每种语言的变量。我设计了一个分类的博客和分类的临时冲洗器函数Hi Abhineet,感谢您的回复,但是:A)我有一个url,它来自变量'idioma',该变量根据所选语言加载admin ajax plus?lang=en或'es',B)我有一个data:action,它可以完美地处理所有内容元素,如果你按下new.whantonline.org上的“加载更多”按钮,你可以检查它唯一的问题是它不接受翻译的类别…非常奇怪。。。
    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;
    });