Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从ajax加载Wordpress特定的帖子模板_Ajax_Wordpress - Fatal编程技术网

从ajax加载Wordpress特定的帖子模板

从ajax加载Wordpress特定的帖子模板,ajax,wordpress,Ajax,Wordpress,我有一个模板portfolio modal.php,它为帖子的模式窗口构建html 我可以从functions.php function ajaxPortfolioItem(){ //get the data from ajax() call $postID = $_GET['postID']; $portfolioItem = get_template_part('portfolio','modal'); die($portfolioItem); } ad

我有一个模板
portfolio modal.php
,它为帖子的模式窗口构建html

我可以从
functions.php

function ajaxPortfolioItem(){  
  //get the data from ajax() call  
   $postID = $_GET['postID'];  
   $portfolioItem = get_template_part('portfolio','modal');
   die($portfolioItem);  
}
add_action( 'wp_ajax_ajaxPortfolioItem', 'ajaxPortfolioItem' ); 
但是如何将
$postID
传递给模板,使其能够呈现正确的帖子呢

这似乎是我见过一百万个主题所做的事情,但我到处搜索,却找不到答案


另外,我不是一个WP的人,所以可能我处理这个问题的方法是错误的。

关于我正在处理的主题,我正在加载一个关于点击事件的特定页面

$(".YourOpeningButton").click(function(){
        var post_link = $(this).attr("href");
        $("#YourContainer").html("loading...");
        $("#YourContainer").load(post_link + " #container > * ");
    return false;
    });
然后,您只需在WP中创建一个页面,并在主题中添加指向该页面的链接

<a href="<?php echo get_option('home'); ?>/YourPage/" class="">link</a>


当您单击您的打开按钮时,它应该检查href并在您的容器中打开此页面。我希望它能帮助…

关于我现在正在处理的主题,我正在加载一个关于点击事件的特定页面

$(".YourOpeningButton").click(function(){
        var post_link = $(this).attr("href");
        $("#YourContainer").html("loading...");
        $("#YourContainer").load(post_link + " #container > * ");
    return false;
    });
然后,您只需在WP中创建一个页面,并在主题中添加指向该页面的链接

<a href="<?php echo get_option('home'); ?>/YourPage/" class="">link</a>


当您单击您的打开按钮时,它应该检查href并在您的容器中打开此页面。我希望它能帮上忙…

哇,我怎么会错过你可以从地址栏访问任何php文件的机会呢。超级简单,谢谢。哇,我怎么没想到你可以从地址栏访问任何php文件。非常简单,谢谢。