Archived topic
[ajax_load_more] shortcode enter with elements
7 replies · Started by Anna De Simone on July 4, 2022
Hello,
I installed the Ajax Load More plug-in (pro version).
So, I should enter/insert the code [ajax_load_more post_type = "post" posts_per_page = "5"]. Can I do it using Elements?
If I cannot use Elements, I have already installed the «generatepress_child» but there, I only have the file style.css and functions.php there is no single.php.
Thanks to anyone who can help me :)
Hi Anna De Simone,
That looks like a Shortcode. So, in the Block Editor, you can add it through a WordPress Shortcode Block. You may also add it through a GP Hook Element, just make sure you enable “Execute Shortcodes”.
You shouldn’t need to use a Child theme to run a shortcode.
Moreover, any plugin coded in line with the WordPress Codex should work as expected with GeneratePress.
Hope this clarifies!
Thanks Fernando,
you have been very kind :)
As you suggested, I use the Hook Element for shortcode.
The problem is that I have to integrate also this code in the single.php and I don't know how to do it without modifying the original GP file.
<?php
// single.php
get_header();
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- #post-wrapper (Ajax Load More target div) -->
<div id="post-wrapper">
<article id="post-<?php echo get_the_id(); ?>" <?php body_class(); ?>>
<h1><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
<footer>
<?php the_tags(); ?>
<?php comments_template(); ?>
</footer>
</article>
</div>
<!-- End #post-wrapper -->
<?php endwhile; endif; ?>
<?php get_footer(); ?>
Thanks for your help
Hi there,
try adding this PHP Snippet to your site:
add_action('generate_before_do_template_part', function(){
if ( is_single() ) {
?>
<!-- #post-wrapper (Ajax Load More target div) -->
<div id="post-wrapper">
<?php
}
});
add_action('generate_after_do_template_part', function(){
if ( is_single() ) {
?>
</div>
<!-- End #post-wrapper -->
<?php
}
});
thanks David, unfortunately your code doesn't work. :))
After several attempts, the addon only works by modifying the single.php file.
How can i create a single.php file in the child theme?
Grazie,
Anna
Hi Anna,
David's code should work, I've tested it on my end.
If you want to go the child theme way, you can take a copy of single.php file from the parent theme, paste it into your child theme folder, then you can modify this file.
Perfect, copying the single.php file in the "child theme" and inserting the code there, everything works fine. Thank you Ying.
You are welcome :)