admin管理员组文章数量:1406444
I like to use ajax to fetch the content of a wordpress page inside my custom templates. I've read that it's necessary to pass all the call to fetch or get data throught the admin-ajax.php
of wordpress. I'm a bit confused on how to proceed, for example if I need to get the content of a post because I want to display it, I need to setup a call to admin ajax or a call to a function file that will hold the php query?Someone guide me.
Sorry for the dumb question, I've never used ajax inside my custom themes or in wordpress in general.
for now I try to use the get_template_part()
function to load custom html code and wp loops, but it's not very suitable for certain theme or app design where ajax will be more smooth and user friendly.
An example of my code for now:
<?php get_header(); ?>
<?php if( have_posts() ); while( have_posts() ): the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
// here fetch the content inside a div instead of using the loop directly
<?php get_footer(); ?>
Is the REST API a good approach?
本文标签: Implement AJAX to fetch pages or posts content in a WordPress custom theme
版权声明:本文标题:Implement AJAX to fetch pages or posts content in a WordPress custom theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745015487a2637813.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论