• Resolved steveforgues

    (@steveforgues)


    I’m trying to figure out how to make my homepage work the way I want, but PHP is a whole new game for me.

    At this point in time I have a static homepage. What I would like to do is have the latest post from a specific category (say Cat 5) to be above the static content on the page. Then below the static content, I want an excerpt from the latest post from any category except the previous one (Cat 5).

    I have no idea how to go about writing the loop for this. I have searched the docs and other sources, but I’m probably more confused now than I was when I started researching this. Thank you to anyone that is able to help.

Viewing 1 replies (of 1 total)
  • Thread Starter steveforgues

    (@steveforgues)

    I figured it out.

    <?php
    /*
    Template Name: Homepage
    */
    ?>
    <?php get_header(); ?>
    
            <div id="content">
    
                <?php $my_query = new WP_Query('cat=12&posts_per_page=1');
                    while ($my_query->have_posts()) : $my_query->the_post();
                    $do_not_duplicate = $post->ID;?>
                        <!-- Looping Code -->
                            <div class="post" id="post-<?php the_ID(); ?>">
                                <p align="center"><strong>Quote of the Day:</strong><br /><em><?php the_content(); ?></em></p>
                            </div>
                <?php endwhile; ?>
                        <!-- Do other Loop -->
                <?php if (have_posts()) : while (have_posts()) : the_post();
                        if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
                            <!-- Looping Code -->
                                <div class="post" id="post-<?php the_ID(); ?>">
                                    <h1 class="title">Welcome to Above Dirt</h1>
                                    <div class="entry">
                                        <?php the_content(); ?>
                                    </div>
                                </div>
                <?php endwhile; ?>
                <?php $my_query = new WP_Query('cat=-12&posts_per_page=1');
                    while ($my_query->have_posts()) : $my_query->the_post(); ?>
                        <!-- Looping Code -->
                            <div class="post" id="post"<?php the_ID(); ?>">
                            <h2 id="post-<?php the_ID(); ?>"><em>Latest Post:</em><br /><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
                                    <p class="byline">
                                        <span class="author vcard">by <?php the_author(); ?></span> on
                                        <abbr class="published" title="<?php the_time(__('l, F jS, Y, g:i a', 'example')); ?>"><?php the_time(__('F j, Y', 'example')); ?></abbr>
                                    </p>
                                <div class="entry">
                                    <?php the_excerpt(); ?>
                                    <p class="links">
                                        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" class="more">Read full article</a>
                                    </p>
                                </div>
                            </div>
            <?php endwhile; endif; ?>
    
            </div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘New to PHP and I need help’ is closed to new replies.