I am trying to write a loop that will pull in posts from the top level site of my multisite installation into the homepage of the sub-sites.
So far I have:
$top_level_posts = new WP_Query("cat=1&posts_per_page=3");
if ($top_level_posts->have_posts()) : while ($top_level_posts->have_posts()) : $top_level_posts->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; else: ?>
<li>More posts coming soon!</li>
Which displays the correct posts but it’s getting the_permalink wrong as it tries to load the post on the subdomain I am trying to display the list on, rather than the proper link to the post on the top-level domain.
So it’s putting:
Can anyone tell me is there a way to trim down the_permalink to strip out the domain name part of the url? As that way I could use
to put the correct domain name at the beginning of the link and then follow on with the rest of the permalink…
I found this post: http://wordpress.org/support/topic/remove-domain-from-get_permalink
which suggests using substr to cut down but that would rely on the subdomain names always being the same length… problem is I have many and they vary in length. They do all end in .com though… so is there a way to strip off anything before (and including) .com maybe?
Or maybe I am just making this whole thing much more complicated than it needs to be!!?
Any suggestions appreciated.