小编Chr*_*ndi的帖子

HTML5 Boilerplate .htaccess缓存无法使用WordPress

.htaccessHTML5 Boilerplate(http://html5boilerplate.com/)的缓存设置非常棒,但我遇到了JS和CSS版本控制的缓存破坏设置问题.

<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我似乎无法使用.htaccess文件中已存在的WordPress重写设置.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

充其量,我的JS文件的重写永远不会发生.在最坏的情况下,它打破了网站.

任何人都有运气使用WordPress吗?

wordpress html5boilerplate

8
推荐指数
1
解决办法
1255
查看次数

使用wp_remote_get在WordPress中使用XML

我怀疑我遗漏了一些非常基本和明显的东西,所以请提前道歉!

我一直在使用simple_xml_loadXML文件,但我的客户端托管提供程序阻止通过此方法加载外部文件.我现在正在尝试使用wp_remote_getWordPress内置的功能重建我的工作.

这是我的代码(注意:在此示例中,密钥和shelter ID是通用的):

$url = "http://api.petfinder.com/shelter.getPets?key=1234&count=20&id=abcd&status=A&output=full";
$pf_xml = wp_remote_get( $url );
$xml = wp_remote_retrieve_body($pf_xml);
Run Code Online (Sandbox Code Playgroud)

使用它,我可以检索我需要的所有数据的数组,但我无法弄清楚如何定位特定数据.以下是从中输出的内容print_r($xml):

<petfinder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://api.petfinder.com/schemas/0.9/petfinder.xsd">
    <header>
        <version>0.1</version>
        <timestamp>2013-03-09T15:03:46Z</timestamp>
        <status>
        <code>100</code>
        <message/>
        </status>
    </header>
    <lastOffset>5</lastOffset>
    <pets>
        <pet>
            <id>13019537</id>
            <name>Jordy</name>
            <animal>Dog</animal>
        </pet>
        <pet>
            <id>13019888</id>
            <name>Tom</name>
            <animal>Dog</animal>
        </pet>
    </pets>
</petfinder>
Run Code Online (Sandbox Code Playgroud)

echo例如,如果我想要状态代码,我该怎么做?使用simplexml,我会写$xml->header->status->code.我似乎无法弄清楚代码结构与使用数组做类似的事情是什么wp_remote_get.

提前致谢!

php xml wordpress

7
推荐指数
1
解决办法
4609
查看次数

WordPress add_rewrite_rule在本地工作,但不在服务器上

我可以add_rewrite_rule在MAMP本地工作,但不能在我的DreamHost生产服务器上工作.

我试图在http://www.pawsnewengland.com/our-dogs-list/上美化个别宠物的网址.丑陋的URL遵循以下结构:our-dogs-list /?view = pet-details&id = 12345,自定义函数使用$_GET变量处理信息.

在我的functions.php文件中,我已经包含了这个:

function rewrite_pet_url() {
    add_rewrite_rule(
        "our-dogs-list/pet-details/([0-9]+)/?$",
        "index.php/our-dogs-list/?view=pet-details&id=$1",
        "top"
    );
}
add_action( 'init', 'rewrite_pet_url');
Run Code Online (Sandbox Code Playgroud)

我也尝试了同样的结果:

function rewrite_pet_url() {
    add_rewrite_rule(
        "our-dogs-list/pet-details/([0-9]+)/?$",
        "index.php/our-dogs-list/?view=pet-details&id=$matches[1]",
        "top"
    );
}
add_action( 'init', 'rewrite_pet_url');
Run Code Online (Sandbox Code Playgroud)

为了简单地测试重写是否会起作用,试过这个:

function rewrite_pet_url() {
    add_rewrite_rule(
        "fake",
        "index.php/about",
        "top"
    );
}
add_action( 'init', 'rewrite_pet_url');
Run Code Online (Sandbox Code Playgroud)

我在测试之前刷新重写规则,并确认重写规则已添加到.htaccess文件中.但是,出于某种原因,我看到的是404页面或白色屏幕并且"未指定输入文件".

我能够在本地工作,所以我不知道在现场服务器上有什么打破.任何见解?

更新1

我已经将重写"工作",因为它不再导致任何错误.不幸的是,它现在导致不必要的重定向到根URL.

function rewrite_pet_url() {
    add_rewrite_tag('%view%','([^&]+)');
    add_rewrite_tag('%id%','([^&]+)');
    add_rewrite_rule(
        'our-dogs-list/pet-details/([0-9]+)?$',
        'index.php/?page_id=1663&view=pet-details&id=$1',
        'top'
    );
}
add_action( 'init', 'rewrite_pet_url' );
Run Code Online (Sandbox Code Playgroud)

有了这个,我可以使用view和访问 …

regex apache wordpress mod-rewrite wordpress-theming

7
推荐指数
2
解决办法
2574
查看次数