• Resolved raj2005

    (@raj2005)


    I have a website and want to display posts from an external website on to my own website so every times the posts update on the external website, it will update on my website too.

    I have managed to pull the posts from the external website on to my website, but now I want them so that when you click them from my website they navigate to the original posts on the original website.

    Please see my code below:

    <?php
    $mydb = new wpdb('root','','test','localhost');
    $rows = $mydb->get_results("select post_title from wp_posts");
    echo '<ul>';
    foreach ($rows as $obj) :
       echo '<li><a href="'.get_permalink($obj->post_title).'">'.$obj->post_title.'</a></li>';
    endforeach;
    echo '</ul>';
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • There’s a plugin called Real-Time Find and Replace (I’m the author) that you might be able to use to change the domain of the links to match your site’s domain. This plugin doesn’t change the actual database content. Instead it modifies the page HTML before it is sent to the user’s browser. So if you turn off the plugin, things go back to the way they were.

    Thread Starter raj2005

    (@raj2005)

    Hi Marious,

    Thanks for your answer but I don’t want to change the URL for the whole website just those posts on the homepage.

    Thread Starter raj2005

    (@raj2005)

    Hi I managed to fix this now for anyone else that may have the same error. I just hardlinked the link:

    <?php
    
    $mydb = new wpdb('root','','test','localhost');
    $rows = $mydb->get_results("select post_title from wp_posts WHERE post_status='publish'");
    echo '<ul>';
    foreach ($rows as $obj) : ?>
    
       <li><a href="http://localhost/database2/2015/11/26/<?php echo $obj->post_title; ?>"><?php echo $obj->post_title; ?></a></li>
    
    <?php
    endforeach;
    echo '</ul>'; 
    
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘want to link the posts on mywebsite back to it's own website where they live’ is closed to new replies.