• 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.

Viewing 15 replies - 1 through 15 (of 16 total)
  • 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.

    Thread Starter benbailey

    (@benbailey)

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

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

    Thanks

    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 https://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’);
    ?>

    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?

    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.

    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

    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.

    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.

    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).

    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.

    ldotb

    (@ldotb)

    I get

    Fatal error: Call to undefined function: query_posts()

    moshu

    (@moshu)

    Did you follow the first 5 lines from this link?

    ldotb

    (@ldotb)

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

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘how to display WP content outside of WP’ is closed to new replies.