• https://www.ahy4life.com/update_20121008/

    The above is a testing site. I need to add additional categories but cannot seem to fathom precisely the proper code for a specific section on each page. An rtfm has been unsuccessful.
    For example, if I wish to display the title and then the content from a post from ‘events’, which is ID=4, in the code below:


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

    <h2><center><?php the_title(); ?></center></h2>

    <!– Display the Post’s Content in a div box. –>

    <?php the_content(); ?>

    <?php endwhile; else: ?>
    <p><?php _e(‘Sorry, no posts matched your criteria.’); ?></p>
    <?php endif; ?>

    what is the proper code?

Viewing 2 replies - 1 through 2 (of 2 total)
  • What you could do is use WP_Query and pull the latest post from the category, so something like this:

    <?php
    	$new_query_1 = new WP_Query();
    	$new_query_1->query(array( 'posts_per_page' => 1, 'cat' => 4 ));
    	?>
    	<?php while ($new_query_1->have_posts()) : $new_query_1->the_post(); ?>
    	<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
            <?php the_content() ;?>
    <?php endwhile; ?>
    Thread Starter biggupp

    (@biggupp)

    Can’t get it to quite work. I admit I am a bit of a novice with WP.
    Is there not a way to simply specify the category in the existing code?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Proper Code to Display Posts from Specific Categories’ is closed to new replies.