• 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.

    Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter xmatter

    (@xmatter)

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

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

    Thread Starter xmatter

    (@xmatter)

    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.

    Thoughts?

    Thread Starter xmatter

    (@xmatter)

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

    <?php
    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.]

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

    Thread Starter xmatter

    (@xmatter)

    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.

    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.

    Thread Starter xmatter

    (@xmatter)

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

    Thanks

    Have a look at the Usage section in https://codex.www.ads-software.com/Using_Custom_Fields

    Thread Starter xmatter

    (@xmatter)

    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.

    Thread Starter xmatter

    (@xmatter)

    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:

    <?php
    
    		query_posts('showposts=-1&cat=4&orderby=rand');
    
    		if (have_posts()) : while (have_posts()) : the_post();
    		?>
    
    		<ul class="category-list-styling">
    
    			<li>
    
    			<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>
    			</div>
           			</li>
    		</ul>
    
    		<?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.