• Resolved eguru

    (@eguru)


    Hello All,
    I am working on a website where I have links (Main Navigations) news gallery, awards, competition etc.. I would like to make these links to direct to the recent post from the each category which I have mentioned above. example if some one clicks on the NEWS link it the recent post from the NEWS category will open. I am using currently this code

    <div id="home"><?php
    global $post;
    $latest_posts = get_posts('numberposts=1');
    foreach($latest_posts as $latest) {
    	echo '<a href="'.get_permalink($latest->ID).'" class=main_menu_links>NEWS</a>';
    }
    ?></div>

    If it is only one category this can work well. What if different categories like the one which I have mentioned above? Please help me if you have any answer. Your help will be highly appreaciate.

    Thank you in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • If news gallery, awards, competition etc are categories and if you are using wp_list_categories to display navigation menu, won’t it link to the recent posts from that particular category…

    Thread Starter eguru

    (@eguru)

    <?php wp_list_categories( ); ?> will only list the category links..it will not show the posts. What I need is if i click on the main menus (category name) i will be ale to see the recent post in side that particular gallery. Just like we are clicking on a static websites main Links.

    Thread Starter eguru

    (@eguru)

    Please help me!!!! any body here?

    <?php
    global $post;
    $cats = get_categories();
    foreach($cats as $cat){
     $myposts = get_posts('numberposts=1&category=$cat->term_id');
     foreach($myposts as $post) :
       setup_postdata($post);
       echo '<a href="'.the_permalink().'" class=main_menu_links>'.$cat->name.'</a>';
     endforeach;
    }
    ?>

    cicking on the category names form your sidebar should show the all the posts from that category

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to make links on the header to the recent posts ?’ is closed to new replies.