0

I have a static website and WordPress installed at mywebsite.com/blog.

I have a page on my external static website which displays a list of all posts [per the codex][1] using the following code

<div class="container" id="blog-home">     
<div class="col-md-8 col-sm-8 col-xs-12">
  <?php
  $args = array( 'numberposts' => 10,    'post_status'=>"publish",'post_type'=>"jobs",'orderby'=>"post_date");
  $postslist = get_posts( $args );
  foreach ($postslist as $post) : setup_postdata($post); ?>
     <div class="post">
        <h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <p><?php the_date(); ?></p>
                 <p><?php the_excerpt(); ?></p>
    </div>
  <?php endforeach; ?> 
</div>

I then have tried to create a page which can display a single post with

<?php
// Include WordPress
 define('WP_USE_THEMES', false);
  require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
 query_posts('showposts=1');
?>

 <div class="col-md-8 col-sm-8 col-xs-12">

    <?php while (have_posts()): the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_excerpt(); ?>
    <p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p>
    <?php endwhile; ?>

</div>

The bit I'm missing is getting the Title on the first page (which lists all posts) to link to the right single post.

Basically I'm trying to avoid having to go to the wordpress blog at all but always running the loop outside of WordPress. Is this possible and could anyone help me fill in this gap!?

Cheers

  • This code works but you can't get the anchor right? Is that the question? – s_ha_dum Feb 27 '14 at 14:35
  • Yea the first page displays the list of posts. I can get the second page to display a single post. But I can't get the titles on the first page to link to the single post page I have created - that would need to display the post of the title that was clicked. – Ciarán Feb 27 '14 at 18:01
  • The code is your first block looks right to me. There must be something happening in code not posted, or your description of the problem is still missing something. – s_ha_dum Feb 27 '14 at 18:06
  • Maybe it's my description of the problem. The link I have: <a href="<?php the_permalink(); ?>" is always going to link to the wordpress blog is that right? So it will link to mywordpressblog.com/the-post. I need it to link to the page that I have created and show that post within the loop that I have put there. So I have tried to create my own version of single.php which will display individual posts from the Custom Post Type 'jobs' which I have created that exists on my external website. I hope that clarifies it a bit! – Ciarán Feb 27 '14 at 22:06
0

You should rewrite the_permalink() function.

http://your_blog_addres/<?php the_slug(); ?>

should be what you are looking for.

  • 1
    Would you mind explaining this? – tfrommen Feb 27 '14 at 15:04
  • I might have understood your question wrong, but you said you are getting wrong links to single posts in that page where you are running the loop. So I gave you a solution. Or you get wrong post slugs? – Mindaugas Jakubauskas Feb 27 '14 at 15:06
  • Hi Mindaugus I asked the question and someone else has asked you to explain it but I don't think it's the right solution. What I need is for the title of the post to link to a page template running the loop which would show that post. So I have already created a page for the single post to display but I can't figure out how to display the post that you would be directed to when you click the post title. Does that make sense!? Thanks for the suggestion – Ciarán Feb 27 '14 at 17:59
  • the_permalink() should produce that URL and should do so in a much more robust way than your code, which is entirely dependent on permalink settings. – s_ha_dum Feb 27 '14 at 18:03
  • I misunderstood what he was asking for. I thought he doesn't get correct permalink. – Mindaugas Jakubauskas Mar 5 '14 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.