Forums

Showing Categories on Pages in Post form? Also problem with title. (4 posts)

  1. Belle224
    Member
    Posted 1 year ago #

    Hi, I need help with showing categories on pages in post form. I've searched online, there are a ton of things except they don't work for me...

    I just copied my index.php file onto a new template, but changed it up and added the code below. However, when I try to add another post that's also in the same category, it doesn't show up. Instead, it just shows one post (I did a test drive and there's only 2 posts and only one post showed). Also, in my page template it displays the title of the Page on each page automatically, so instead of the post title showing, the name of the Page shows for the title.

    Possibly there is another code I should be using instead? And how would I fix the other problems I've said above...?

    I found the code below on the internet.

    <?php
    $myposts = get_posts('numberposts=5&category=4');
    foreach($myposts as $post) :
    	setup_postdata($post);
            //add in standard WordPress post specific template tags here eg. the_title(), the_permalink, the_content, the_excerpt etc.
    endforeach;  ?>

    Here is my template that I've made: http://pastebin.com/dKhCCUmG
    Here is my Page template: http://pastebin.com/zPa6tMms

  2. Jeremy Boggs
    Member
    Posted 1 year ago #

    It sounds like you're running into problems trying to run multiple loops on one template. The Loop page on the Codex has specific instructions on how to work with multiple loops. Doing this correctly will prevent the page title for showing up for you second loop of posts, and likely will solve your issue of not returning all your posts. There are a few examples on the codex page that might help you out.

  3. Belle224
    Member
    Posted 1 year ago #

    Sorry I'm new to WordPress and I'm not so good with coding... could you clarify or maybe show me the improved code? If it's not too much trouble.

    Thanks in advance.

  4. Belle224
    Member
    Posted 1 year ago #

    Nevermind, I've actually found a plugin.

    After spending an extremely long time searching I've found a plugin that actually works!

    http://wordpress.org/extend/plugins/pages-posts/

Topic Closed

This topic has been closed to new replies.

About this Topic