• Resolved daand

    (@daand)


    <?php
     $postslist = get_posts('numberposts=10&orderby=title');
     foreach ($postslist as $post) :
        setup_postdata($post);
     ?>

    I need the php code beneath”

    <?php
    $category = get_the_category();
    echo $category[0]->cat_ID;
    ?>

    To be inserted in the code above.

    So i can display: get_posts('numberposts=10&category=.......&orderby=title');
    and replace ….. with the cateogry ID number.

    Does anyone understand this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • How about:

    <?php
    $category = get_the_category();
    $cat_id = $category[0]->cat_ID;
    $postslist = get_posts('numberposts=10&orderby=title&cat=' . $cat_id);
    foreach ($postslist as $post) :
    setup_postdata($post);
    ?>

    Do you mean

    get_posts('numberposts=10&category=' . $category[0]->cat_ID . '&orderby=title');

    Don’t you have to use cat for category ids? Or have I missed something?

    Righto!

    get_posts('numberposts=10&cat=' . $category[0]->cat_ID . '&orderby=title');
    Thread Starter daand

    (@daand)

    Esmis solution worked!!
    Thanks very much!!

    Thread Starter daand

    (@daand)

    What if i want to exclude the current post in the get posts code?

    $postslist = get_posts('numberposts=1000&order=ASC&exclude=....&orderby=date&cat=' . $cat_id);

    In which case … should be the current post ID.

    The current post ID template tag is; the_ID() I thought.

    I would very much appericiate it when someone could explain how it works, because i dont want to bother you every time..

    Thanks in advance!
    Daan

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP code in template tag’ is closed to new replies.