• magicsun

    (@magicsun)


    Hi There,

    I have found loads of topics on this on the forum, but none can help me out i’m afraid.

    A client wants 3 categories displayed on the same page. Because I don’t want them to mess with the layout, it needs to be done with php/html etc. So that they only need to add the messages to the proper category.

    Layout should be like this:

    —————

    Title page

    Quick story that tells what to see below.

    Category 1 title

    Title post 1
    message

    Title post 2
    message

    Category 2 title

    Title post 1
    message

    Title post 2
    message

    Category 3 title

    Title post 1
    message

    Title post 2
    message

    —————-

    I want the posts to appear together per category, not in a mix.

    What I thought I could do is enter the PHP for calling the category and posts inside that category. I have Exec-PHP installed, so I can use php in pages/posts. Or use a template, but I thought this was just a matter of calling the category through php .. I could be wrong !

    Can anybody help me out?

    I know there is a loop page, and query posts etc, but they don’t give the example i’m looking for since I need multiple loops. I can’t write PHP myself, therefor I can’t adjust a code.

    Hope someone is willing to lend me a hand !

    Greetings,
    Mirna

Viewing 7 replies - 1 through 7 (of 7 total)
  • Michael

    (@alchymyth)

    Thread Starter magicsun

    (@magicsun)

    Thank you for your help .. but …

    I have added this:

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

    I get 3 times “No Posts for”. Deleted the mark-up for the actual posts, doesn’t make a difference.

    Thread Starter magicsun

    (@magicsun)

    I know what to use, I just don’t know how to use it .. that’s my biggest problem. I see all those topics pointing to the get_post and query_posts but it’s all chinese to me really … Especially since I want to have 3 categories, not one. One is simple, just make a menu.

    Thanks for your effort and help, I really appreciate it.

    esmi

    (@esmi)

    Something like this should work.

    <?php $cat_array = array(1,2,3); // ids of categories needed
    foreach( $cat_array as my$cat) :
    $args = array( 'numberposts' => 2, 'cat' => $mycat );
    $myposts = get_posts( $args );
    foreach($myposts as $post) : setup_postdata($post); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_excerpt();
    endforeach; endforeach; ?>
    Thread Starter magicsun

    (@magicsun)

    @ esmi, Thanks, but your code gave me a parse error.

    I ended up using this: http://pastebin.com/qzkAzqQd

    <offtopic> I really don’t agree with my post being edited, I think this pastebin is not doing any good to this forum, because now I can’t search for codes anymore. Probably why I couldn’t find my solution. If you can’t post any codes longer then 10 lines here, then what’s the use? isn’t this forum to help each other?

    Just my 2 cents … </offtopic>

    esmi

    (@esmi)

    What was the parse error? Bear in mind that the code snippet was written off the top of my head.

    Thread Starter magicsun

    (@magicsun)

    Parse error: syntax error, unexpected T_VARIABLE, expecting T_PAAMAYIM_NEKUDOTAYIM in

    and then pointing to the file I had past the code in. It says line 20.
    foreach( $cat_array as my$cat) :

    that is that line. I don’t know the exact error it had before, just quickly pasted your code into it again in my current template, but the name of the parse error is the same. Now It doesn’t even view the page, It did before (just showed the error inside the page).

    I also need to have anchors right before the category titles and with only one php code I can’t do that myself. That’s why I used the three seperate ones now, so that I can insert my own text/code inbetween.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add multiple category posts on one page’ is closed to new replies.