WP:如果声明

时间:2012-11-15 15:36:09

标签: php wordpress if-statement

我在WordPress中创建了一个2语言网站,我需要说:

如果html方向是RTL,则使用其他代码使用其他代码...

我用我在Joomla中使用的传统方式尝试了这个。

<?php    if( $this->direction=="rtl"){ ?>
        /images/slider/01.jpg“alt =”Slider 01“title =”#htmlcaption“/&gt; /images/slider/02.jpg”alt =“Slider 02”title =“#htmlcaption”/&gt; /images/slider/03.jpg“alt =”Slider 03“title =”#htmlcaption“/&gt; /images/slider/04.jpg”alt =“Slider 04”title =“#htmlcaption”/&gt;        هذامثاللمايمكنانيكتبهنا。                             /images/slider/01.jpg“alt =”Slider 01“title =”#htmlcaption“/&gt; /images/slider/02.jpg”alt =“Slider 02”title =“#htmlcaption”/&gt; /images/slider/03.jpg“alt =”Slider 03“title =”#htmlcaption“/&gt; /images/slider/04.jpg”alt =“Slider 04”title =“#htmlcaption”/&gt;          提供具有成本效益和可靠的海上运输        是带有链接的HTML标题的示例。        是带有链接的HTML标题的示例。        是带有链接的HTML标题的示例。     

但它总是说有一个致命的错误..我想我需要将$this定义为html页面 但是怎么说在PHP?

:在第7行的C:\ AppServ \ www \ wordpress \ wp-content \ themes \ wp \ index.php中不在对象上下文中时使用$ this

2 个答案:

答案 0 :(得分:2)

看起来我们内置了另一个名为“language_attributes()”的函数。试试这个:

// if ( function_exists( 'is_rtl' ) ) # You may need to utilize this if is_rtl() is not defined
if( is_rtl() == 'rtl' ){
    // DO RTL code
}else{
    // DO LTR code    
}

基于以下信息:

http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/general-template.php#L0

http://wpml.org/2011/06/creating-right-to-left-rtl-wordpress-sites/

http://codex.wordpress.org/Right-to-Left_Language_Support

答案 1 :(得分:0)

试试这个:

$script_name=$_SERVER['SCRIPT_NAME'];