WordPress.org

Ready to get started?Download WordPress

Forums

How to Display Posts from a specific Category in a Page (8 posts)

  1. Jam
    Member
    Posted 2 years ago #

    How can I do this? I've researched plugins and possible code, but it all seems outdated. Also, I would like to write text about the running posts, almost as an intro to the page.

    Thanks in advance!

  2. Th3Crazy3st
    Member
    Posted 2 years ago #

    <?php $posts = get_posts('category=3&orderby=rand&numberposts=5'); foreach($posts as $post) { ?>
    <a href="<?php the_permalink() ?>" target="_parent"><?php the_title(); ?></a>
    <?php } ?>

    Use css to make it look nice, use li, ul etc.

    If you want to insert that in page.php you can make a new template.

    Create newpage.php and copy there what is in page.php

    On top of newpage.php (first line) add this:

    <?php /* Template Name: New Page */ ?>

    Now when you want to create a new page and insert all that posts from categories -> Pages -> Add new page -> Page Attributes -> Template -> New Page

    And you're done. I hope you get it. Regards.

  3. Jam
    Member
    Posted 2 years ago #

    Great! Thank you! I know this is a newbie question, but how can I relate categories to category #'s or IDs?

    Also, how can I add more than 1 category?

  4. Jam
    Member
    Posted 2 years ago #

    Ok, I found a plugin that does this.

    How can I display the posts just like the blog?

  5. Jam
    Member
    Posted 2 years ago #

    Ok, I think I solved my problem with the following code I combined the blog page, a regular page, and your filter code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    But for some reason, my footer is messed up

  6. Jam
    Member
    Posted 2 years ago #

    Ok, I fixed that. Now how can I limit the number of posts that it shows

  7. Jam
    Member
    Posted 2 years ago #

    I have this so far, but the post titles are all the same and I cant limit the # of posts. Any help appreciated!

    <?php get_header(); ?>
        <div id="content">
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div <?php if(function_exists('post_class')) : ?><?php post_class(); ?><?php else : ?>class="post post-<?php the_ID(); ?>"<?php endif; ?>>
    			<h2 class="entry-title"><?php the_title(); ?></h2>
    			<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    			<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    		</div>
    	</div>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    
    <?php
    /*
    Custom Code (Pi Code) That allows you to display posts from a given Category. THIS IS WHAT YOU UPDATE EACH YEAR!
    */ ?>
    
    	<div id="content">
    		<h2 class="entry-title"><?php the_title(); ?></h2>
    		<?php
    		$temp = $wp_query;
    		$wp_query = NULL;
    		$wp_query = new WP_Query();
    		$wp_query->query('&paged='.$paged);
    		while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    		<?php $posts = get_posts('category=7,21&numberposts=5&showposts=5'); foreach($posts as $post) { ?>
    
    		<?php } ?>
    
    		<div <?php post_class(); ?>>
    			<h3 class="entry-title"><p align="left"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s','gpp_i18n'),the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h3></p><br>
    			<div class="entry">
    				<?php global $more; $more = 0; the_content(); ?>
    				<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'gpp_i18n' ), 'after' => '</div>' ) ); ?>
    			</div><div class="clear"></div>
    		</div><div class="clear"></div>
    		<p class="postmetadata"><?php the_time(__('M d, Y', 'gpp_i18n')); ?> | <?php _e('Categories: ','gpp_i18n'); if (the_category(', '))  the_category(); ?> <?php if (get_the_tags()) the_tags(__('| Tags: ','gpp_i18n')); ?> </p>
    		<?php endwhile; ?>
    		<div class="nav-interior">
    			<div class="prev"><?php next_posts_link(__('&laquo; Older Entries','gpp_i18n')); ?></div>
    			<div class="next"><?php previous_posts_link(__('Newer Entries &raquo;','gpp_i18n')); ?></div>
    		</div><div class="clear"></div>
    		<?php $wp_query = NULL; $wp_query = $temp;?>
    	</div>
    
    	<?php
    /*
    End Custom Code
    */ ?>
    
    <?php get_footer(); ?>
  8. syamexpress
    Member
    Posted 1 year ago #

    Please help me how to post order by descending order

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags