检查URL是否包含某些单词php wordpress


Check if URL contains certain word php wordpress

我只想显示网址中包含某个单词的帖子。我得到了这个,但它不起作用。我想要网址中包含博客或新闻的所有帖子。

    <?php 
$url = $_SERVER["REQUEST_URI"];
$isItBlog = strpos($url, 'scotch');
$isItNews = strpos($url, 'soda');
if ($isItBlog!==false)
{ 
?>
<h1 class="cat">Worked with - </h1>
               <h1 class="entry-title"><a title="<?php printf( esc_attr__( 'Permalink to %s', 'compass' ), the_title_attribute( 'echo=0' ) ); ?>" href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?>
               </a></h1>
               <div class="clearfix"></div>
        <?php the_post_thumbnail( 'category-thumb'); ?>
               <div class="entry-content"><?php the_content(); ?></div>

<?php
}
if ($isItNews!==false)
{
?>
     <h1 class="entry-title"><a title="<?php printf( esc_attr__( 'Permalink to %s', 'compass' ), the_title_attribute( 'echo=0' ) ); ?>" href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?>
               </a></h1>
               <div class="clearfix"></div>
        <?php the_post_thumbnail( 'category-thumb'); ?>
               <div class="entry-content"><?php the_content(); ?></div>
<?php } ?>
       </article>

问候

这个最好的解决方案。

 $url = 'http://terra.com.br/soda';
 if(strpos($url, 'scotch') == true){
   $value = 'scotch';
 } else if (strpos($url, 'soda') == true){
  $value = 'soda';
 } else {
   $value = 'error';
}
echo $value;