WordPress.org

Ready to get started?Download WordPress

Forums

Display Certain Posts within a Page (13 posts)

  1. xmatter
    Member
    Posted 2 years ago #

    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!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

  3. xmatter
    Member
    Posted 2 years ago #

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

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  5. xmatter
    Member
    Posted 2 years ago #

    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?

  6. xmatter
    Member
    Posted 2 years ago #

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

  7. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  8. xmatter
    Member
    Posted 2 years ago #

    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.

  9. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    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.

  10. xmatter
    Member
    Posted 2 years ago #

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

    Thanks

  11. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  12. xmatter
    Member
    Posted 2 years ago #

    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.

  13. xmatter
    Member
    Posted 2 years ago #

    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(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.