• WordPress is in a /blog folder. I want to include WordPress posts in my homepage (index.php) at the root. Simple, right?

    I know this is a basic question that has been asked many times before! I’ve never had any problems with it, until I installed 2.5.1 and turned on fancy permalinks. I then got this: ‘Sorry, no posts matched your criteria’.

    I’ve posted another version of this question here and on several other related threads, but haven’t received answers on any of them.

    The only documentation on this seems to be Creating a Static Front Page, but it’s only gives a solution for title links with no pointers how to get full posts. The mini-loop solution is very different from the old WordPress solution and raises lots of questions.

    Am I missing something? What has changed in 2.5.1 that makes it suddenly impossible to include blog posts on an outside page?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    What has changed in 2.5.1 that makes it suddenly impossible to include blog posts on an outside page?

    Nothing, you were just doing it wrong in the first place. Not your fault though…

    Add a call to the query_posts function before your own Loop. If you don’t query the posts, it doesn’t know what posts you want.

    Previous versions defaulted to the normal “blog homepage” posts. However, this was a side effect, not by design. Newer versions do not default to anything, as it was supposed to be in the first place. Therefore you have to specify what posts you want. A simple query_posts(‘showposts=5’) to get 5 posts or something will do.

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    Thanks Otto42!

    This now works:

    <?
    query_posts('showposts=5');
    
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div class="post" id="post-<? the_ID(); ?>">
    <h3 class="storytitle"><a href="<? the_permalink() ?>" title="<? the_title(); ?>" rel="bookmark"><? the_title(); ?></a></h3>
    <div class="info">Posted by <? the_author() ?> on <? the_time('F') ?> <? the_time('j') ?>, <? the_time('Y') ?> under <? the_category(',') ?> <? edit_post_link(__('Edit This')); ?></div>
    
    <div class="storycontent">
            <? the_content(__('Read the rest of this entry &raquo;')); ?>
    </div>
    
    <div class="info">
    		<? wp_link_pages(); ?>
    		<? comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
        </div>
    
    </div>
    
    <? comments_template(); // Get wp-comments.php template ?>
    
    <? endwhile; ?>
    
    <div class="alignleft"><? next_posts_link('&laquo; Previous Entries') ?>
    </div>
    <div class="alignright"><? previous_posts_link('Next Entries &raquo;') ?>
    </div>
    
    <? else : ?>
    
    <? _e('Sorry, no posts matched your criteria.'); ?>
    
    <? endif; ?>

    Why does ‘Creating a Static Front Page’ give that weird alternative solution?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Why does ‘Creating a Static Front Page’ give that weird alternative solution?

    Dunno, but that page is also extremely old. Static front pages changed heavily starting with WordPress 2.3.

    An alternative for those not wanting to use WP templates at all. This is simpler although you have to be careful what is being selected is what you want. The example assumes you have PEAR:DB or MDB2 installed but it’s simple to convert to use ‘normal’ PHP mySQL built in commands

    /*
     * getLatestBlogEntries
     * Connects to the WP blog DB and retrieve latest 8 postings
     * formatting them in HTML
     *
     */
    function getLatestBlogEntries() {
    
    	$blogSQL = "SELECT * FROM wp_posts
    					WHERE post_type = 'post' AND 	post_status = 'publish' ORDER BY post_date DESC LIMIT 8";
    
            // Connect to db and perform query
    	$dbBlog = DB::connect(BLOG_DB_DSN, true);
    	$resBlog =& $dbBlog->query($blogSQL);
    
            // loop through result set building links to blog posts
    	$html = '<ul>';
    	while($resBlog->fetchInto($blogEntry, DB_FETCHMODE_OBJECT)) {
    	$html .= '<li><a>ID.'" title="'.stripslashes($blogEntry->post_title).'">'.$blogEntry->post_title."</a></li>\n";
    	}
    	$html .= "</ul>\n\n";
    
            // return resulting unordered list of latest blog entry links
    	return $html;
    
    }
    ?>

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    query_posts(‘showposts=5’); doesn’t work anymore in 2.7

    What’s the latest way to do this (2.6 officially I guess)?

    Any ideas on this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Blog posts on a page outside WordPress’ is closed to new replies.