如何使用Ajax显示字preSS查询如何使用、Ajax、preSS

2023-09-10 21:51:22 作者:初恋只是一场小感冒.

试图显示使用jQuery是给我一些麻烦的内容。我创建了三个按钮,点击后,他们从我的服务器上的PHP文件加载数据。一切正常,只是当我尝试发送一个请求装入字preSS职位。下面的致命错误出现:调用未定义功能get_posts()。我学会了如何从 HTTPS做到这一点://perishable$p$pss.com/slide -fade内容/ 。

有关的脚本,我有这样的:

&LT;脚本类型=文/ JavaScript的SRC =HTTP:// ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> &LT;脚本类型=文/ JavaScript的SRC =htt​​p://example.com/slide-fade-content/jquery.colorfade.min.js&GT;&LT; / SCRIPT&GT; &LT;脚本类型=文/ JavaScript的&GT; //幻灯片和放大器;褪色的内容@ http://m0n.co/r $(文件)。就绪(函数(){ $('更')。在('点击',功能(五){ 即preventDefault(); VAR HREF = $(本).attr(HREF'); 如果($('#AJAX)是(:可见)){ 。$('#AJAX')的CSS({显示:'块'})动画({高度:0})空()。 } $('#AJAX')的CSS({显示:'块'})。动画({高度:为200px},函数(){ $('#阿贾克斯)HTML('&LT; IMG ID =加载SRC =loader.gif&GT;'); $('#装载机)的CSS({边界:'无',位置:相对,上面:24PX',离开了:48像素,boxShadow:'无'}); $('#阿贾克斯)。负载(幻灯片淡出content.php'+ HREF,函数(){ $('#阿贾克斯)隐藏()淡入(慢)colorFade({'fadeColor':'RGB(253253175)'}); }); }); }); }); &LT; / SCRIPT&GT;

苹果6怎么在屏幕上显示字

这些是我的三个按钮:

&LT; UL&GT;   &LT;李&GT;&LT;一类=更多的href =#第一个项目&gt;首先项目&lt; / A&GT;&LT; /李&GT;   &LT;李&GT;&LT;一类=更多的href =#第二个项目&gt;第二个项目&lt; / A&GT;&LT; /李&GT;   &LT;李&GT;&LT;一类=更多的href =#第三项&GT;三是项目&lt; / A&GT;&LT; /李&GT; &LT; / UL&GT;

这是出现的内容,其中

&LT; D​​IV ID =AJAX&GT;&LT; / DIV&GT;

这是内容

&LT; D​​IV ID =负荷&GT;   &LT; D​​IV ID =第一项&GT;     &LT; PHP       $ ARGS =阵列(       posts_per_page'=&GT; 5,       '抵消'=&GT; 0,       '类'=&GT; '2,3,4',       排序依据=&GT; meta_value_num,       meta_key'=&GT; 若干意见,       为了'=&GT; 降序,       SUP press_filters'=&GT;真正,         date_query'=&GT;阵列(            '后'=&GT;日期(JS F,Y的strtotime(' - 24小时))             ) );     $ myposts = get_posts($参数);     的foreach($ myposts为$后):setup_postdata($后); ?&GT;       &LT; D​​IV&GT;          &LT;李&GT;             &LT; UL&GT;&LT; PHP $类别= get_the_category(); $分隔符=''; $输出=''; 如果($类){ 的foreach($类别$类){ $输出='&LT; A HREF =。get_category_link($分类 - &GT; term_id)。'称号='esc_attr(sprintf的(__(查看所有在%s),$类别 - &GT;名))'&GT;'。$类别 - &GT; cat_name'&所述; / a取代;。$隔板。 } 回声修剪($输出,$分隔符); } ?&GT;            &LT; / UL&GT;         &LT; A HREF =&LT; PHP the_permalink();?&GT;&GT;&LT; PHP的回声get_the_post_thumbnail($的post_id,阵列(300,160),$ ATTR); ?&GT;         &LT; A HREF =&LT; PHP the_permalink();?&GT;&GT;&LT; PHP the_title(); ?&GT;         &LT; /李&GT;       &LT; / DIV&GT;               &LT; PHP endforeach;   wp_reset_postdata();?&GT; &LT; / DIV&GT;     &LT; D​​IV ID =第二项&GT; TEST2     &LT; / DIV&GT;     &LT; D​​IV ID =第三项&GT; TEST3 &LT; / DIV&GT;      &LT; / DIV&GT;

我想我必须定义一个函数,但我失去了好几个小时的反复试验后。我无法弄清楚如何做到这一点,或在哪里定义它。

解决方案

这听起来像你的脚本幻灯片淡出content.php没有实例字preSS所以你不能打电话的话preSS功能 get_posts(),你会得到未定义函数的错误调用。

如果您包括您的Word preSS配置文件,您将能够使这个词preSS API调用。

  require_once [路径到Word preSS安装]的/ wp-config.php文件。
 

Trying to display content using jQuery is giving me some trouble. I’ve created three buttons, when clicked they load data from a php file on my server. Everything works except when I try to send a request to load Wordpress posts. The following fatal error appears: Call to undefined function get_posts(). I learned how to do this from https://perishablepress.com/slide-fade-content/.

For the scripting, I have this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="http://example.com/slide-fade-content/jquery.colorfade.min.js"></script>

<script type="text/javascript">
// slide & fade content @ http://m0n.co/r
$(document).ready(function() {
	$('.more').on('click', function(e) {
		e.preventDefault();
		var href = $(this).attr('href');
		if ($('#ajax').is(':visible')) {
			$('#ajax').css({ display:'block' }).animate({ height:'0' }).empty();
		}
		$('#ajax').css({ display:'block' }).animate({ height:'200px' },function() {
			$('#ajax').html('<img id="loader" src="loader.gif">');
			$('#loader').css({ border:'none', position:'relative', top:'24px', left:'48px', boxShadow:'none' });
			$('#ajax').load('slide-fade-content.php ' + href, function() {
				$('#ajax').hide().fadeIn('slow').colorFade({ 'fadeColor': 'rgb(253,253,175)' });
			});
		});
	});
});
</script>

These are my three buttons:

<ul>
  <li><a class="more" href="#first-item">First Item</a></li>
  <li><a class="more" href="#second-item">Second Item</a></li>
  <li><a class="more" href="#third-item">Third Item</a></li>
</ul>

This is where the content appears

<div id="ajax"></div>

And this is the content

<div id="load">
  <div id="first-item">
    <?php
      $args = array( 
      'posts_per_page' => 5, 
      'offset'=> 0, 
      'category' => '2,3,4', 
      'orderby' => 'meta_value_num',
      'meta_key' => 'views',
      'order' => 'DESC',
      'suppress_filters' => true,
        'date_query' => array(
           'after' => date("jS F, Y", strtotime('-24 hours')) 
            )
);

    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
      <div>
         <li>

            <ul><?php $categories = get_the_category(); $separator = ' '; $output = '';
		       if($categories){
			    foreach($categories as $category) {
			     $output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
			}
				echo trim($output, $separator)			;
			}
			?>
           </ul>

        <a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail( $post_id,  array(300, 160), $attr ); ?>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
        </li>
      </div>
           
  <?php endforeach; 
  wp_reset_postdata();?>

	</div>
	
    <div id="second-item">
			Test2
	
    </div>
	
    <div id="third-item">
			Test3
	</div>
    
</div>

I think I have to define a function, but after many hours of trial and error I’m lost. I can't figure out how to do it or where to defines it.

解决方案

It sounds like your script slide-fade-content.php is not instantiating WordPress so you are not able to call the WordPress function get_posts() and you get the error call to undefined function.

If you include your WordPress config file you will be able to make calls on the WordPress API.

require_once [path to WordPress install].'/wp-config.php';