• Is there any way to retrieve the main subsite slug?

    Here’s what I’m trying to do exactly… I have https://website.com set up as a multisite for SEO purposes, and created subsites:

    https://website.com/ — global site
    https://website.com/san-diego/ — san diego store
    https://website.com/los-angeles/ — los angeles store
    https://website.com/denver/ — denver store

    Now, each of these subsites has a navigation structure that’s part of the template. They’re called through a php include() function for the sake of maintaining graphics, classes, and styles universally (so using the wp_list_pages is no good). Also, I only want to use one template file (header.php).

    THE PROBLEM I’m facing is figuring out how to add the main multisite slug into the links. So let’s say we’re on the Global site (https://website.com/), right now we get this:

    <li><a href="/services/p1">Service 1</a></li>
    <li><a href="/services/p2">Service 2</a></li>
    <li><a href="/services/p3">Service 3</a></li>
    <li><a href="/services/p4">Service 4</a></li>

    Which is great… but once we get onto the San Diego site (https://website.com/san-diego/), we want this:

    <li><a href="/san-diego/services/p1">Service 1</a></li>
    <li><a href="/san-diego/services/p2">Service 2</a></li>
    <li><a href="/san-diego/services/p3">Service 3</a></li>
    <li><a href="/san-diego/services/p3">Service 4</a></li>
    <li><a href="<?php multisite-slug; ?>/services/p1">Service 1</a></li>

    …and similar for Los Angeles, Denver, etc.. Any great method to achieve this? Hopefully this is pretty clear for what I’m asking for.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter rssolo23

    (@rssolo23)

    PS: I’m open to using PHP conditional statements and having more than one include file… but if I can avoid it, I’d prefer to do so.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    It may be worth your time to grab this plugin https://www.ads-software.com/extend/plugins/diamond-multisite-widgets/ and crack it open. I know it has a blog list, and you could leverage THAT code to automate the output.

    Thread Starter rssolo23

    (@rssolo23)

    It seems like he’s using SQL to pull the information directly from the database.

    I found this function to work just fine:

    <?php get_blog_option( $blog['blog_id'], 'siteurl' ); ?>

    so we simply place it as:

    <li><a href="<?php echo get_blog_option( $blog['blog_id'], 'siteurl' ); ?>/services/p1">Service 1</a></li>
    <li><a href="<?php echo get_blog_option( $blog['blog_id'], 'siteurl' ); ?>/services/p2">Service 2</a></li>
    <li><a href="<?php echo get_blog_option( $blog['blog_id'], 'siteurl' ); ?>/services/p3">Service 3</a></li>
    <li><a href="<?php echo get_blog_option( $blog['blog_id'], 'siteurl' ); ?>/services/p3">Service 4</a></li>

    and now if we click through the different sites (global, san diego, los angeles, etc..) we should see the URL of those links work properly. It doesn’t necessarily turn it into a slug, but it does the job exactly how I need it.

    Thanks again for all your help ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multisite Slug question — simple but complex?’ is closed to new replies.