wp擷取目前網址.

在wordpress 中,你可能會想要如何擷取當前頁面的網址(current url),以下我們就來看看php的作法:

<?php
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo site_url(). “/” . rtrim(get_the_title($ID),’-283′) ;
endwhile;
wp_reset_postdata();
?>

這樣的作法是可以直接顯示當前的頁面,然後讀出目前的網址,其中rtim()這是php的函數,主要功能是消除字串,而’-283’就是要消除的字串。