如第页所示http://localhost/wordpress/about_us/
如何仅获取“about_us
“?
谢谢
如第页所示http://localhost/wordpress/about_us/
如何仅获取“about_us
“?
谢谢
WP全局变量$pagename应该对您可用,我刚刚使用了您指定的相同设置进行了尝试。
$pagename在文件wp includes/theme中定义。php中的函数get\\u page\\u template(),它当然是在解析页面主题文件之前调用的,因此它在页面模板中的任何位置都可用。
虽然似乎没有记录,但$pagename
仅当使用永久链接时才设置var。我想这是因为如果你不使用它们,WP不需要页面slug,所以它不会设置它。
$pagename
如果将页面用作静态首页,则不会设置。
这是/wp includes/theme中的代码。php,在无法设置$pagename时使用您指出的解决方案:
$pagename = get_query_var(\'pagename\');
if ( !$pagename && $id > 0 ) {
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
$post = $wp_query->get_queried_object();
$pagename = $post->post_name;
}
我想知道如何翻译下面的内容index.php (或category.php 使用qtranslate?)。我用的是“212”主题。上的我的代码index.php: <?php /** * The main template file. * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ ?> <?php get_head