首先抱歉我的英文不好,我用ajax加载更多,当我点击我的类别(商店或产品)时链接到页面achive.php
- http://localhost/technology-wordpress/tech_blogs/shop/
- http://localhost/technology-wordpress/tech_blogs/product/
我希望从archive.php页面获取第三段以传递到我的查询页面(fetch_blog.php)(商店,产品)以传递我的查询
'taxonomy' => 'tech_blog_categories',
'field' => 'slug',
'terms' => third_segment
'include_children' => false
这是我的代码
fetch_blog.php
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
if ( get_query_var('paged') ) $paged = get_query_var('paged');
if ( get_query_var('page') ) $paged = get_query_var('page');
$args = array(
'post_type' => 'tech_blog',
'posts_per_page' => 2,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'tech_blog_categories',
'field' => 'slug',
'terms' => third_segment
'include_children' => false
)
)
);
$the_query = new WP_Query( $args );
$posts =$the_query ->posts;
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) : $the_query->the_post();?>
<?php endwhile;
}
?>
achive.php
<div class="col-md-12" id="results"></div>
<p class="load_more load-more_tech_blog">
<a id="load_more_button" class="btn-load">Load More</a>
</p>
</div>
<input type="hidden" value="<?= get_home_url() ?>" id="site_url">
<script type="text/javascript">
var track_page = 1;
load_contents(track_page); //load content
$("#load_more_button").click(function (e) { //user clicks on button
track_page++; //page number increment everytime user clicks load button
load_contents(track_page); //load content
});
function load_contents(track_page){
var url = $("#site_url").val();
$('.animation_image').show(); //show loading image
$.post( url + '/fetch_blog', {'page': track_page}, function(data){
if(data.trim().length == 0){
$("#load_more_button").text("You have reached end of the record!").prop("disabled", true);
}
$("#results").append(data); //append data into #results element
$("#load_more_button").offset().top}, 800);
$('.animation_image').hide(); //hide loading image once data is received
});
}
</script>