Support » How-To and Troubleshooting » Display Certain Posts within a Page

Display Certain Posts within a Page

  • I am looking to display certain posts (based on category) within a page or page template. So let’s say the post “french fry” was in the “food” category and i want only “food” related posts to display with the “food” page.

    I have tried to build a php on my own, but no success. Can anyone help me out with this?

    I plan on having 30 categories and 30 pages… 1 cat for 1 page.


Viewing 12 replies - 1 through 12 (of 12 total)
  • esmi
    Forum Moderator


    Thanks for the response. That is exactly what I was looking for, expect I do not have the “custom field” within my post/page?

    Forum Moderator


    There’s nothing about custom fields in the Page of Posts example.

    here is a snippet:

    “A Page Template that displays posts from a specific category depending on a Custom Field assigned to a Page. In this example the value of the Custom Field “category” is retrieved and used as the category to retrieve the posts in that category. So if the category of posts you want to display is called “Events” then assign the Custom Field “category” with a value of “Events” to the Page. “

    The instruction say to add a custom field of “EVENTS” so the template knows to only display posts relating to EVENTS. I do not have the custom field entry on a NEW POST.


    wait… i believe i figured it out. I have to replace category with food?

    if (is_page() ) {
    $category = get_post_meta($posts[0]->ID, '<strong>category</strong>', true);
    if ($category) {

    [Please post code snippets between backticks or use the code button.]

    Forum Moderator


    Are you going to create a custom template for every one of these 30 pages?

    i could if that’s what it would take, but rather use one template and somehow apply a category to the page itself and let WP do all the work.

    Forum Moderator


    and somehow apply a category to the page itself

    Since Pages don’t have categories, that’s why you need to add the custom field (eg a field called category with the value food) to the page.

    how do i go about doing that? i am a little confused with this process.


    Forum Moderator


    Have a look at the Usage section in http://codex.wordpress.org/Using_Custom_Fields

    i have looked at all you posted, but still get the “Not Found” on the Books page.

    I have created a post category called books. ($type = books)

    I have created a post (checked “books” category) and added a custom field to the post, both key and value are books.

    here is the Page of Books template (saved as books.php)

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

    Somewhere along the line i am becoming confused with this process.

    I have created this code to randomize the posts from each particular category on each separate page. I guess will just have to create a template for each page that i wish to do this on. Here it is:

    		if (have_posts()) : while (have_posts()) : the_post();
    		<ul class="category-list-styling">
    			<a href="<?php the_permalink(); ?>" class="category-list-styling-title"><?php the_title(); ?></a>
    			<div class="entry">
    			<?php the_excerpt(); ?>
    				<a href="<?php the_permalink(); ?>" title="Read the rest of <?php the_title(); ?>" class="read-more-link">read more</a>
    		<?php endwhile; endif; ?>	
    		<?php wp_reset_query(); ?>
Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Display Certain Posts within a Page’ is closed to new replies.