I have a WordPress network with multiple sites using the same theme. Now I need to edit part of a certain PageTemplate.php
to display different things based on the blog id
.
Example:
If blog ID 1, run this:
<a href="<?php if(get_post_meta($post->ID, 'videoembed_videopopup', true)): ?><?php echo get_post_meta($post->ID, 'videoembed_videopopup', true) ?>
<?php else: ?>
<?php if(get_post_meta($post->ID, 'links_link_custom', true)): ?><?php echo get_post_meta($post->ID, 'links_link_custom', true) ?>
<?php else: ?>
<?php the_permalink(); ?>
<?php endif; ?><?php endif; ?>" class="hover-gradient <?php if(get_post_meta($post->ID, 'videoembed_videopopup', true)): ?>video-pop-up<?php endif; ?>" target="_blank" <?php if(get_post_meta($post->ID, 'videoembed_videopopup', true)): ?>rel="prettyPhoto"<?php endif; ?>><?php the_post_thumbnail('progression-thumb-retina'); ?></a><?php endif; ?>
else, run this:
<?php if(get_post_meta($post->ID, 'links_link_custom', true)): ?>
<a href="<?php echo get_post_meta($post->ID, 'links_link_custom', true) ?>" class="hover-gradient <?php if(get_post_meta($post->ID, 'videoembed_videopopup', true)): ?>video-pop-up<?php endif; ?>">
<?php else: ?>
<?php if(get_post_meta($post->ID, 'videoembed_videopopup', true)): ?>
<a href="<?php echo get_post_meta($post->ID, 'videoembed_videopopup', true) ?>" class="hover-gradient <?php if(get_post_meta($post->ID, 'videoembed_videopopup', true)): ?>video-pop-up<?php endif; ?>">
<?php else: ?>
<?php endif; ?><?php endif; ?>
<?php the_post_thumbnail('progression-thumb-retina'); ?></a>
<?php endif; ?>
I found this conditional which I believe is the way to accomplish my objective:
<?php
global $blog_id;
if ($blog_id == 1) {
code here;
}
else {
code here;
}
?>
How can I put the two blocks of codes inside the blog id conditional, is it possible? If not, is there another way to do this?
You can do it like this:
Here’s the whole prettified version of the code you can use (totally UNTESTED, but should work unless there are any silly mistakes that I didn’t notice):
If you’re trying to distinguish between your network’s “main” site and any others, you can use the conditional tag
is_main_site()
: