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.