• Resolved Bill Milhoan

    (@bill_milhoan)


    Hello,

    I’m not new to web design; just new to WordPress. I’ve spent days trying to figure out how to post one post from a category on the static page I use as the home page. I found a hunk of code that seems to do the trick:

    <div class="feature-box">
    <!--===== THE LOOP =====-->
    <?php
    $the_query = new WP_Query( 'category_name=next-concert' ); ?>
    <?php if ( $the_query->have_posts() ) : ?> 
    
    <!-- the loop -->
    <div class="concert-info">
      <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
      <h1>
        <?php the_title(); ?>
      </h1>
      <p>
        <?php the_content(); ?>
      </p>
      <?php endwhile; ?>
    <!--===== END OF CONCERT INFO =====-->
    <!-- end of the loop -->
    </div>

    I’ve auditioned many themes and even written my own but smpl-skeleton seems to have what I need all in one place. So, the secret to gaining my happiness seems to be gaining an understanding of the process of assigning a custom loop file (loop-home-page.php) to the home page. However, I don’t seem to be able to wrap my head around the flow of the template. Which file is actually the home page? Do I need to alter the function.php file to point to the custom loop page or is that taken care of in a different manner? Or is it possible to change the above code with a condition that the post only happens on the home page?

    Thanks for your help. Links to references would be awesome – there seems to be a lot of very old info out there and I’ve spent days going through it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • FOLLOW UP:

    I’m wondering if this chunk of code is part of the answer:

    <?php
                if ( have_posts() ) :
                    // Start the Loop.
                    while ( have_posts() ) : the_post();
    
                        /*
                         * Include the post format-specific template for the content. If you want to
                         * use this in a child theme, then include a file called called content-___.php
                         * (where ___ is the post format) and that will be used instead.
                         */
                        get_template_part( 'content', get_post_format() );
    
                    endwhile;
                    // Previous/next post navigation.
                    twentyfourteen_paging_nav();
    
                else :
                    // If no content, include the "No posts found" template.
                    get_template_part( 'content', 'none' );
    
                endif;
            ?>

    I found it on the Elegant Themes blog.

    Theme Author simplethemes

    (@simplethemes)


    Hi Bill,

    I’m not sure what version of the theme you’re using but you may be overthinking it.

    Hopefully (if you’re using the latest theme from the WordPress repository) you have the companion shortcodes plugin installed with the theme:
    https://wordpress.org/plugins/smpl-shortcodes/

    To call up a post from a category into a static page, you could use the [latest] shortcode as documented best here:

    http://themes.simplethemes.com/synapse/latest-posts-shortcode-documentation

    For example, this would show a single post from category ID #4 with the excerpt:

    [latest excerpt="true" num="1" cat="4"]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Best Practice?’ is closed to new replies.