使用帖子ID在Bootstrap Modal中加载Wordpress帖子

时间:2015-05-07 14:37:26

标签: php wordpress twitter-bootstrap

我无法解决这个问题。 我需要在Bootstrap模式中加载一个外部帖子。仅使用帖子ID。 这是一个网页,因此所有帖子都会加载到索引中,而不会单独显示。

我使用此example

并且它正常工作只是通过GET挂起'ID'。 这个链接: 'href ='/ cargarnota.php?ids ='正确调用外部文件。

但是当我在'cargarnota.php'文件中添加循环或查询时,模态停止工作。

这是cargarnota.php文件:

<?php
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' );
?>

<?php
$Id = $_GET['ids'];


$content_post = get_post($Id);
$title = $content_post->post_title;
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
$enlace = post_permalink( $Id );
?>


<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><b><i class="indicator flaticon-close33"></i></b></button>
    <p class="enviar-nota">Enviar nota</p>
    <?php echo '<h4 class="verde">' . $title . '</h4>'; ?>
</div>
<div class="modal-body">    
    <?php 
echo $content;
echo post_permalink( $Id ); 
    ?>

</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

该代码不起作用且模态不显示。

但是这个工作正常:

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Enviar nota</h4>
</div>

<div class="modal-body">

<?php 
$id = $_GET['ids'];
echo $id;
?>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

此代码显示模式和ID。

有人知道如何让它发挥作用。?

1 个答案:

答案 0 :(得分:0)

cargarnota.php文件丢失app.factory('bkgndUpdates', function($interval, $q, $rootScope, dataContext, localStorage) { var _interval = null; var _service = { get isRunning() { return _interval != null }, }; _service.start = function() { if( _interval != null ) return; _interval = $interval(function() { // check to ensure local storage is actually available // and has visits to process var visits = localStorage.visits; if( !visits || (visits.length == 0) ) return; var recorded = []; var promises = []; var offline = false; for( var idx = 0; idx < visits.length; idx++ ) { var visit = visits[idx]; promises.push(dataContext.doVisitAction("/Walk/RecordVisit", visit) .then( function(resp) { offline &= false; var home = dataContext.findHomeByID(visit.addressID); if( home != null ) { // these values should cause a map icon to switch from yellow to blue // elsewhere in the app that's what happens...but not here. home.visitInfo.isDirty = false; home.visitInfo.inDatabase = true; home.visitInfo.canDelete = true; home.visitInfo.followUpID = resp.FollowUpID; } recorded.push(visit.addressID); }, function(resp) { // something went wrong; do nothing, as the item is already // in local storage offline |= true; }) ); } $q.all(promises).then( function(resp) { for( var idx = 0; idx < recorded.length; idx++ ) { localStorage.removeVisitByID(recorded[idx]); } if( !localStorage.hasVisits ) { $interval.cancel(_interval); _interval = null; } $rootScope.$emit("visitUpdate"); }, function(resp) { alert("some promise failed"); }); }, 30000); } _service.stop = function() { $interval.cancel(_interval); _interval = null; } return _service; }); 因此wordpress功能未加载,因此get_post并未将帖子内容打印到屏幕上。由于远程内容未加载,因此模式失败。

海报现在修改了问题以包含wp-load.php,这似乎解决了原始代码的问题。