WordPress.org

Ready to get started?Download WordPress

Forums

how to display WP content outside of WP (17 posts)

  1. benbailey
    Member
    Posted 9 years ago #

    i have wordpress set up here:
    mywebsite.com/blog/

    i would also like to display the heading and date of each article on my site's homepage.
    mywebsite.com/
    this is outside of the WP folders and if i try to use code from the existing templates the functions stop working.

    with 1.2 i could hack the code to get this info to display on the homepage but with 1.5 this does not seem possible. :(

    i know that 1.5 has the nice feature of being able to create stand along pages but AFAIK they can only "stand alone" within the directory WP is intalled in.

    any help is appreciated.

  2. Lorelle
    Member
    Posted 9 years ago #

    So you need to turn your index.html into index.php (or whatever your "home" page is) and then add The Loop in the spot where you want the information to appear. There's a little more to it, but that's the start of it.

    Some of the complications hit when jumping folders. Your blog is set up to look for its data in mysite.com/blog/ and you will be asking it to find information from mysite.com/ - I'll leave that answer to those more up on the PHP functions.

  3. benbailey
    Member
    Posted 9 years ago #

    excellent! got it working now.
    thanks for the advice lorelle. :)

  4. anathema
    Member
    Posted 9 years ago #

    Can you share how you did it please? I imagine you just have to change/add some paths right? Need the dirty details.

    Thanks

  5. Marcos Sader
    Member
    Posted 9 years ago #

    Actually is pretty easy, just add these at the beginning of the page you want the wp_functions to work in....

    <?php
    require('blog/wp-blog-header.php');
    ?>

    Let's say that your wp is in http://mysite.com/blog/ so, you need to call the "wp-blog-header.php" that will be on the root of wp (/blog/).. and that's all now the only thing you need to do is use the common wp ffunctions... list_categories, archives, links, etc...

    And you can also call the archives templates by using:
    <?php get_header(); ?>
    <?php get_sidebar(); ?>

    or, if you want the whole site to apear on the index, add define('WP_USE_THEMES', true); so it will look like...

    <?php
    /* Short and sweet */
    define('WP_USE_THEMES', true);
    require('blog/wp-blog-header.php');
    ?>

  6. anathema
    Member
    Posted 9 years ago #

    All i really want to do is display the latest post... do i just add:

    <?php
    require('blog/wp-blog-header.php');
    ?>

    to the top of the page and then put the loop where i want the post to appear?

  7. anathema
    Member
    Posted 9 years ago #

    ha... figured it out. of course just inserting the loop gives you all the posts... duh! but i played around with the loop code and figured out how to limit it to just the latest post. this was actually remarkable for me because i don't know bleep about php. so... for all those who happen to stumble upon this thread... this is what the original loop looks like in 1.5

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post">
    <h2 id="post-<?php the_ID(); ?>">" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>

    <div class="entry">
    <?php the_content('Read the rest of this entry »'); ?>
    </div>

    <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit','','|'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>

    <!--
    <?php trackback_rdf(); ?>
    -->
    </div>

    <?php endwhile; ?>

    <div class="navigation">
    <div class="alignleft"><?php posts_nav_link('','','« Previous Entries') ?></div>
    <div class="alignright"><?php posts_nav_link('','Next Entries »','') ?></div>
    </div>

    <?php else : ?>

    <h2 class="center">Not Found</h2>
    <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>

    <?php endif; ?>

    change the first line to:

    <?php if (have_posts()) : the_post(); ?>

    and remove these two lines:

    <?php while (have_posts()) : the_post(); ?>
    <?php endwhile; ?>

    you could also remove other stuff like the navigation... just take it out.

  8. davidchait
    Member
    Posted 9 years ago #

    note that can be a bit wasteful if your blog is set to show a large number of posts per page, as the loop does the single query to start (though this may have changed slightly in 1.5...).

    d

  9. anathema
    Member
    Posted 9 years ago #

    I am sure there is a better way. Like i said, i don't know anything about php. I was simply impressed that i got it to work.

    I should point out, if you have not gathered this yourself, my intentions with this method. I simply want to display the latest post, say in a 'news' column or div, and thus the user can choose to read more, and be taken to the actual blog.

    i would be curious to know how to set the number of visible posts. with this method i can get the latest, or revert back to using the loop and get them all. it would be nice to display the 5 most recent, or any # for that matter.

  10. Marcos Sader
    Member
    Posted 9 years ago #

    The code you need to use is the following....

    <div>
    <h2>Last Entry</h2>
    <?php
    $posts = get_posts('numberposts=1');
    foreach ($posts as $post) :
    ?>

    <div class="post">
    <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    <small><?php the_time('l, F jS, Y') ?></small>

    <div class="entry">
    <?php the_excerpt() ?>
    </div>

    <p class="postmetadata">Posted in <?php the_category(', ') ?></p>

    </div>

    <?php
    endforeach;
    ?>
    </div>

    Where $posts = get_posts('numberposts=1'); is the func that will let you control the number of post to show in below... you can also use offset=0' attribute to skip some of them, defaults to "0" so will show the 1st, 2nd and on...
    But let's say you want to skip the first, to make a lsit of all recent post except the latest.. you can do this

    <?php
    $posts = get_posts('numberposts=3&offset=1');
    foreach ($posts as $post) :
    ?>

    And will skip the last post, showing the previous 3....

    Hope this solves your problem.

  11. bpolhemus
    Member
    Posted 9 years ago #

  12. privatestorm
    Member
    Posted 9 years ago #

    Is there a special trick to get this to work with a subdomain? My blog is on my main site (www.mainsite.com) but I want to include some WP stuff on a static page on a subdomain (subdomain.mainsite.com).

  13. AwZaM
    Member
    Posted 9 years ago #

    I'm having trouble with this myself. I've posted

    <?php
    require('blog/wp-blog-header.php');
    ?>

    at the top of my page (above all the other html)

    I then insert the code anathema suggested, with the modifications. I then get a page of warnings. Nothing else renders. Are you all using Stylesheets? I have a plain index.php file I'm trying to integrate the most recent post into my index.

  14. LdotB
    Member
    Posted 7 years ago #

    I get

    Fatal error: Call to undefined function: query_posts()

  15. moshu
    Member
    Posted 7 years ago #

    Did you follow the first 5 lines from this link?

  16. LdotB
    Member
    Posted 7 years ago #

    I got it to work...I was using url instead of actual path.

  17. moshu
    Member
    Posted 7 years ago #

    Great to hear it works. (Yeah, url is not working)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.