return $r; } /** * @param int $page 页数 * @param int $pagesize 每页显示数量 * @return mixed */ function link_find($page = 1, $pagesize = 100) { $arr = link__find($cond = array(), array('rank' => -1), $page, $pagesize); return $arr; } /** * @param $id * @return bool 返回FALSE失败 TRUE成功 */ function link_delete($id) { if (empty($id)) return FALSE; $r = link__delete(array('id' => $id)); link_delete_cache(); return $r; } //--------------------------kv + cache-------------------------- /** * @return mixed 返回全部友情链接 */ function link_get($page = 1, $pagesize = 100) { $g_link = website_get('friends_link'); if (empty($g_link)) { $g_link = link_find($page, $pagesize); $g_link AND website_set('friends_link', $g_link); } return $g_link; } // delete kv and cache function link_delete_cache() { website_set('friends_link', ''); return TRUE; } ?>How to reload a php script, using AJAX and jQuery
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to reload a php script, using AJAX and jQuery

programmeradmin1浏览0评论

Good evening, im a beginner in WordPress and i'd like some advices. I have a php script that load some articles thumbnails randomly according to some parameters.

<div id="logos  " class="slide colonne">
<?php
$posts = array(
'posts_per_page' => 5,
'orderby' => 'rand',
'meta_query' => array(
    array(
     'key' => '_thumbnail_id',
     'compare' => 'EXISTS'
    ),
)
);
$query = new WP_Query($posts);
while($query->have_posts()) : $query->the_post(); ?>
<?php echo '<div class="colonne"><a href="' . get_permalink( $_post->ID ) . '" target="_blank" title="' . esc_attr( $_post->post_title ) . '">';
echo get_the_post_thumbnail( $_post->ID, 'thumbnail' );
echo '</a></div>'; ?>
<?php endwhile; ?>
</div>

It is located in wp-content\themes\childtheme\parts\logos.php and loaded in my footer.php

<?php get_template_part('parts/logos'); ?>

The result is working pretty well but now, i'd like it to autorefresh each x seconds. So i've looked for a method to do it and i've come upon this topic: And thus here is my script:

jQuery(function($) {
var refresh = function(){
  $("#logos").fadeOut("slow").load("/wp-content/themes/capitaine/parts/logos.php").fadeIn("slow");

}
setInterval(refresh, 3000 );  ///////// 30 seconds
 });

I've included it in my functions.php

wp_enqueue_script(
        'jquery',
        '.3.1/jquery.min.js',
        false,
        '3.3.1',
        true
    );
wp_enqueue_script(
    'refresh',
    get_template_directory_uri() . '/js/script.js',
    array( 'jquery' ),
    '1.0',
    true
);

But then i was getting this error

The only way i've found to arrange this is from this topic:

I've added <php $abs_path= __FILE__; $get_path=explode('wp-content',$abs_path); $path=$get_path[0].'wp-load.php'; include($path); ?> to the top of my script and it's kinda working, but not according to the css i've defined. So here are my questions: Is that method good ? If not, i would take any good advices. And if it is ok, i would know why the is not in adequation with the css anymore.

e.g. Before the reloading: After the reloading:

Thanks for yours answers and sorry for my messy english and my messy explication.

发布评论

评论列表(0)

  1. 暂无评论