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

    (@raptrex)

    here it is on pastbin
    https://paste.uni.cc/17953

    This gets 3 posts from one category and 3 posts from another… Get all 6 posts from the same category first:
    $posts = get_posts( "category=2&numberposts=6" );

    You only need one “foreach()” loop, but instead of doing
    foreach( $posts as $post )
    make it:

    foreach( $posts as $num => $post ):
        if ( $num == 0 ) // this is the first post
        else // these are the rest

    Thread Starter raptrex

    (@raptrex)

    thx for the reply

    this is what you meant right?
    https://paste.uni.cc/17955

    ill test it when i get home

    Thread Starter raptrex

    (@raptrex)

    alright testing the code out and got some problems
    the_content doesnt show anything, just a </p> with no <p>

    next the “url” or second category only shows the latest post in pright and none of the others
    pright works fine for the first category chat

    heres my index.php
    https://paste.uni.cc/17957

    Raptrex, get_posts() returns an array of objects. You can either use setup_postdata($post); just after foreach(), or apply individual filters like this:
    echo apply_filters('the_title', $post->post_title);
    etc.

    Thread Starter raptrex

    (@raptrex)

    thx azaozz
    it worked until i started adding more stuff and posts

    now my categories are not in order in the <h2> part such as here
    <h2><?php the_category(', '); ?> &raquo;</h2>

    its suppost to show categories 1,4,3 in that order
    but it shows 3,1,4
    the posts show up fine in its correct categories
    just this h2 part is out of order

    my latest code
    https://paste.uni.cc/17998

    all of my posts are in a single category, none are in both 3 and 4 or anything like that

    Thread Starter raptrex

    (@raptrex)

    lol just made another category “6”
    so i replaced 1 with 6

    now it shows 6,6,4
    when its suppose to be 6,4,3

    oh and im doing this on my computer, not on a server

    The current code runs loop whitin a loop whitin a loop… You’re missing the endforeach;. Put one of them just before each endif;, like this:
    endforeach;endif;

    Or if you prefer, use the other syntax with the curly brackets – see the examples here.

    Thread Starter raptrex

    (@raptrex)

    if i add endforeach; before each endif, i get this error

    Parse error: parse error, unexpected T_ENDFOREACH in C:\xampplite\htdocs\wordpress\wp-content\themes\mag\index.php on line 35

    with line 35 and each other line with causing this error being
    <?php endforeach;endif; ?>

    then i tried using the curly brackets

    <?php foreach( $posts as $num => $post ) {
    	setup_postdata($post);
        if ( $num == 0 ) {// this is the first post ?>

    taking out the colon “:”
    i got an error with line 34
    endforeach;
    that i had previously so i deleted that
    and this just messed everything up…

    Yea, it’s my error. The pastebin doesn’t highlight the code properly and I didn’t notice it.

    It looks ok, perhaps you have some posts in more than one cat or in a sub-cat, they will be listed twice.

    Thread Starter raptrex

    (@raptrex)

    nope, all of my posts are in a single category

    Thread Starter raptrex

    (@raptrex)

    lol anyone else that can help? so far only azaozz, whom i appreciate for replying, has helped

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘help with this code’ is closed to new replies.