• Resolved mdesign-1

    (@mdesign-1)


    Hi
    Im trying to get a list of posts from a specific category.
    at the moment i only have the list of categories showing (see code below)

    <div class="box">
                 <ul>
                    <?php //wp_list_bookmarks(); ?>
                     <?php wp_list_categories('title_li=<h2>' . __('Categories') . '</h2>' ); ?>
                 </ul>
            </div>

    Can anyone please help, i just seem to be going in circles and pulling my hair out lol

    MANY THANKS ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • <?php
    //get 3 posts from category id 7
    $args=array(
      'cat' => 7,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 3,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Perhaps try the List category posts plugin.

    Thread Starter mdesign-1

    (@mdesign-1)

    Thanks MichaelH
    Trying not to sound stupid but where do i put this?
    i would guess at the first php line?
    <?php //wp_list_bookmarks(); ?>

    And sorry vtxyzzy this plugin does not suit what i want to use it for ?? thanks for the help any way =)

    Thread Starter mdesign-1

    (@mdesign-1)

    Scrap that ive just given it a go and didn’t work ??

    here’s the code ive got plus a probably better explanation:

    <div class="box">
                 <ul>
                    <?php //wp_list_bookmarks(); ?>
                     <?php wp_list_categories('title_li=<h2>' . __('Categories') . '</h2>' ); ?>
                 </ul>
            </div>
            <div class="box">
                 <ul>
                    <?php //wp_list_bookmarks(); ?>
                     <?php wp_list_categories('title_li=<h2>' . __('Categories') . '</h2>' ); ?>
                 </ul>
            </div>
            <div class="box">
                 <ul>
                    <?php //wp_list_bookmarks(); ?>
                     <?php wp_list_categories('title_li=<h2>' . __('Categories') . '</h2>' ); ?>
                 </ul>
            </div>

    im trying to display the lists of posts from a different category in each [box].
    (or to be completely honest i want to display posts from a different sub-category)

    Yes you will want to use the code I displayed above for each of your ‘boxes’. Of course you will change the ‘cat’=> x value each time.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

    Thread Starter mdesign-1

    (@mdesign-1)

    OK im getting confused. . .
    doesn’t take much lol

    ive tried adding the code you have given me wich works exactly the same as the code i already had???
    my guess on that issue is the problem im having with cat ID as i dont know the category ID’s. so i tried using slugs instead and that didn’t work, also having tried to change from displaying categories to sub catagories i well ended up with blank pages lol

    Please help ??
    wow i feel thick sometimes ??

    Thread Starter mdesign-1

    (@mdesign-1)

    Hi! OK so got the cat number but how do i link it to sub cat?
    also due to code given it either displays nothing or if i add (see code below) to the end i get it all back but it displays all categories???

    <?php wp_list_categories('title_li=<h2>' . __('Categories') . '</h2>' ); ?>

    So starting again because even im confused now.
    here is my code for one box:

    <div class="box">
                 <ul>
                    <?php //wp_list_bookmarks(); ?>
                     <?php wp_list_categories('title_li=<h2>' . __('Categories') . '</h2>' ); ?>
                 </ul>
            </div>

    i want to display all posts in a sub catagory, the catagory ID (not sub cat ID) is 36

    Sorry im a pain and thank you for the fantastic help and advice so far ??

    wp_list_categories lists just the categories, NOT the posts in those categories.

    Thread Starter mdesign-1

    (@mdesign-1)

    OK so would you be able to help on code for listing posts in a specific sub category?

    See my example above and use the sub-category ID for the 'cat' -> x argument.

    Also see query_posts() for more arguments.

    Note: typically you don’t see posts listing in a header navigation.

    Thread Starter mdesign-1

    (@mdesign-1)

    Ah, Got it!
    Thank you so much ??
    i realised that using your code had worked before but wasnt linking through to some of the css design and looked wrong when actually it was right ??

    Sorry for the hassle ??
    and thanks you so much you a saviour ??

    jannmirch

    (@jannmirch)

    Thank you!! This is exactly what I’ve been looking for. Worked like a charm.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Add category post list in menu (HELP!)’ is closed to new replies.