wordpress:如何检查 slug 是否包含特定单词? [英] wordpress: how to check if the slug contains a specific word?

查看:34
本文介绍了wordpress:如何检查 slug 是否包含特定单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用条件语句来检查 slug 中是否出现两个词(博客和新闻)中的任何一个.如果出现一个,我会显示一个菜单,如果出现另一个,则显示其对应的菜单.

I'm trying to use a conditional statement to check if either of two words (blog & news) appear in the slug. If one shows up I will display one menu, if the other then its corresponding menu shows.

推荐答案

使用 PHP:

$url = $_SERVER["REQUEST_URI"];

$isItBlog = strpos($url, 'blog');
$isItNews = strpos($url, 'news');

if ($isItBlog!==false)
{
    //url contains 'blog'
}
if ($isItNews!==false)
{
    //url contains 'news'
}

http://www.php.net/manual/en/function.strpos.php

这篇关于wordpress:如何检查 slug 是否包含特定单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆