WordPress.org

Ready to get started?Download WordPress

Forums

Exceprt on Static Homepage with a 'Read More' link (3 posts)

  1. leanda
    Member
    Posted 7 years ago #

    Hi

    I'm pulling my hair out with this and would be very grateful for help.

    I've got a static home page and the main blog in a separate directory. I'm using the following code to pull excerpts from posts onto the static home page and I'd like to add a link underneath each excerpt which says something like 'Read More'.

    I'm a total noob, I've looked at the_excerpt_reloaded plugin and can't get it to work on the static home page. And I've tried changing post_excerpt to post_content and then using the 'more' tag and that won't work either.

    Can anyone help? Would be very, very grateful.

    <?php
    $how_many=6;
    require_once("wordpress/wp-config.php");
    $news=$wpdb->get_results("SELECT ID, post_title, post_excerpt FROM $wpdb->posts
    WHERE post_type='post' ORDER BY ID DESC LIMIT $how_many");
    foreach($news as $np){
    echo '
    <h3>ID).'">'.$np->post_title.'</h3>
    <p>'.$np->post_excerpt.'</p>';
    }
    ?>

  2. Kafkaesqui

    Posted 7 years ago #

    With the 'more' quicktag in posts:

    <?php
    $how_many = 6;
    require_once("wordpress/wp-config.php");
    $news = $wpdb->get_results("SELECT ID, post_title, post_content FROM $wpdb->posts WHERE post_type='post' ORDER BY ID DESC LIMIT $how_many");
    foreach($news as $np){
    $post_content = split('<!--more-->', $np->post_content);
    echo '<h3><a href="'.get_permalink($np->ID).'">'.$np->post_title.'</h3><p>'.$post_content[0].'</p>';
    }
    ?>

    Or, more the WP-Way:

    <?php
    $how_many = 6;
    require_once("wordpress/wp-blog-header.php");
    query_posts("showposts=$how_many");
    while( have_posts() ) : the_post();
    ?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_content(); ?>
    <?php endwhile; ?>

  3. leanda
    Member
    Posted 7 years ago #

    Thanks very much.

    I'll try both these methods out today.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic