• I need some help with fine tuning the code for “the LOOP”. I’m trying to pull a query from my weblog into my splash page. I had it working so far, I just would like it to list just one post and link directly to my index.php instead of the individual posts.

    does anyone have an idea how I could hack the code below to achieve my desired result.any thoughts?
    Thank you in advance.

    my current testing splash page is located:
    http://www.chazsouthard.org/splash_3.php


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

    <?php if ( !(in_category(‘3’)) ) { ?>

    <div class=”post”>

    <h2><a>"><?php the_title(); ?></a></h2>

    <small><?php the_time(‘F jS, Y’); ?></small>

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

    </div> <!– closes the first div box –>

    <?php } ?> <!– Close the if statement. –>

    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>`

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter chaz19

    (@chaz19)

    or could I use a mini loop — but also include the excerpt with a date and link to index.php.

    Mini loop code with the just titled displaying no excerpt or date.
    ‘<?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=1; //How many posts do you want to show ?>
    <?
    $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 (”

    • %s
    • “, $np->ID,$np->post_title);
      }?>
      `

    Thread Starter chaz19

    (@chaz19)

    figured it out —
    used the code below:

    <?php
    $posts = get_posts(‘numberposts=1’);
    foreach($posts as $post) :
    ?>
    <h2> <?php the_title(); ?></h2>
    <small><?php the_time(‘F jS, Y’); ?></small>
    <?php the_excerpt(); ?>
    <?php endforeach; ?>

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘need help with hack/php query code’ is closed to new replies.