Viewing 10 replies - 1 through 10 (of 10 total)
  • <?php the_excerpt(); ?>
    is what is normally used for excerpts, but that may not be applicable to the mini-loop solution there. You may also want to see what I’ve done in my latest MilkXT theme.

    You should be able to do that by calling “post_excerpt” in addition to “post_title”. The exact code for doing that isn’t beyond my ken, but I’d suggest repeating that whole mySQL function immediately following the first one and just replacing post_title with post_excerpt.

    Thread Starter Graphics

    (@graphics)

    i hate to sound stupid…
    but to php i am.
    where would i place
    either of these tags to make them work, in accordance with the code i am using?

    Put the code in the Sidebar template file if you want it in your sidebar. Here you go:

    <h2 class="coltitle">Latest News</h2>
    <?php
    $today = current_time('mysql', 1);

    if ( $recentposts = $wpdb->get_results("SELECT ID, post_title, post_excerpt FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5")):
    ?>
    <ul>
    <?php
    foreach ($recentposts as $post) {
    if ($post->post_title == '')
    $post->post_title = sprintf(__('Post #%s'), $post->ID);
    echo "<li><a href='?p=$post->ID'>";
    the_title();
    echo "</a>";
    the_excerpt();
    echo "</li>";
    }
    ?>
    </ul>
    <?php endif; ?>

    Thread Starter Graphics

    (@graphics)

    it didnt work, gave me MySql errors.

    heres the code i am using: ( link at bottom probaby wont be written out due to the way this forum handle code)

    ‘<td>
    <?php define(‘WP_USE_THEMES’, false);
    require(‘./wordpress/wp-blog-header.php’);
    ?>
    <div id=”content” class=”narrowcolumn”>

    <h2>Lastest Posts:</h2>

    <?php
    # Here starts Mini Loop trick: You can use this code, but _at your own risk_
    # If you want to improve this code, you’re welcome 😉
    $how_many=7; //How many posts do you want to show ?>

    <ul align=’left’>
    <?
    $news=$wpdb->get_results(“SELECT ID,post_title FROM $wpdb->posts
    WHERE post_status = \”publish\” ORDER BY ID DESC LIMIT “.$how_many);
    foreach($news as $np){
    printf (“<li align=’left’>%s“, $np->ID,$np->post_title,$np->post_title);
    }?>

    </div>
    </td>’

    This should do what you’re after:

    <?php
    $how_many=5;
    require_once("wp-config.php");
    ?>

    <ol id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT ID, post_title, post_excerpt FROM $wpdb->posts
    WHERE post_status='publish' ORDER BY ID DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href="index.php?p=%s">%s</a>%s
    </li>", $np->ID,$np->post_title,$np->post_excerpt);
    }?>
    </ol>

    Note it displays an excerpt if a post actually has an excerpt, as in text entered in the excerpt field. It does not extract and excerpt from the post’s content, like the_excerpt() would. Here’s a version based more on WordPress’ own functionality:

    <?php
    $how_many=5;
    require_once("wp-config.php");
    ?>

    <ol id="whats-new">
    <?php $news = new WP_Query("showposts=$how_many");
    while($news->have_posts()) : $news->the_post();
    ?>
    <li><a href="index.php?p=<?php the_ID(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt(); ?>
    </li>
    <?php endwhile; ?>
    </ol>

    Thread Starter Graphics

    (@graphics)

    both gave this error

    Parse error: parse error, unexpected T_STRING in /usr/local/apache2/vhosts/osga/feedtest.php on line 44

    And line 44 in feedtest.php is?

    I’ve just run the code bits on my test site, and both worked without error except I noticed <a href="index.php?p=%s"> was missing the slashes before each " in the first one I posted (it’s not needed in the second). Still, that wouldn’t cause a T_STRING error.

    Thread Starter Graphics

    (@graphics)

    BIG THANKS!
    apparently the first time i tried it, it was “user error”
    one or two more fixes and i’ll be stylin!

    Hmm…no idea why that would have given you mySQL errors. I tested it here – http://www.tom-hanna.net/testblog/ – before I posted it and all I did was copy and paste.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘code for including “excerpts” in headlines’ is closed to new replies.