简体   繁体   English

WordPress主题不同的URL

[英]Wordpress theme different URL

I have 2 domains sharing the same Wordpress theme. 我有2个域共享相同的Wordpress主题。 I don't want to manage 2 separate themes, but there are a few small differences in the sites. 我不想管理2个单独的主题,但是网站上有一些小的差异。 I want to do something similar to the: 我想做类似的事情:

<?php if ( is_page( 'Contact' )) { ?>
  <!-- Contact content -->
<?php } else { ?>
  <!-- Other content -->
<?php } ?>

But instead of looking for a page, it is looking for a different full URL: Such as http://example.com versus http://example.net . 但是,它不是在寻找页面,而是在寻找其他完整的URL:例如http://example.comhttp://example.net

You can try this: 您可以尝试以下方法:

<?php if ( $_SERVER['HTTP_HOST'] == 'example.net' ) : ?>
    <div> Example.net</div>
<?php else : ?>
    <div> Example.com</div>
<?php endif; ?>

Or if you want to use regex: 或者,如果您想使用正则表达式:

<?php if ( preg_match('/\.example.net/', $_SERVER['HTTP_HOST']) ) : ?>
    <div> Example.net</div>
<?php else : ?>
    <div> Example.com</div>
<?php endif; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM