WordPress.org

Ready to get started?Download WordPress

Forums

Listing Custom Post Types (1 post)

  1. kirkward
    Member
    Posted 1 year ago #

    I have a website running as a Multisite Network. In the sidebar, I have a "tabber" with three tabs. On the three pages of this tabber, I want to list the posts in each of three Custom Post Types, one type on each page of the tabber.

    The Custom Post Types plugin generates archive pages (not Category pages) at http://mydomain.com/press-releases/ ... http://mydomain.com/news/ ... and http://mydomain.com/events/

    I have posts in each of those types, so I can navigate to them by using those URL's.

    To get the list of posts on each tab, I have added code to my theme functions.php and changed the code in my tabber.php

    Here is the code I added to the theme functions.php ...

    # Added To List Custom Posts In Tabber
    function tj_tabs_news($posts = 5) {
        $news = query_posts( array( 'post_type' => 'news', 'posts_per_page' => $posts ) );
        while ( have_posts() ) : the_post();
    ?>
    <li>
         <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <div class="clear"></div>
    </li>
    <?php endwhile;
    }
    
    function tj_tabs_press($posts = 5) {
        $news = query_posts( array( 'post_type' => 'press-releases', 'posts_per_page' => $posts ) );
        while ( have_posts() ) : the_post();
    ?>
    <li>
         <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <div class="clear"></div>
    </li>
    <?php endwhile;
    }
    
    function tj_tabs_events($posts = 5) {
        $news = query_posts( array( 'post_type' => 'events', 'posts_per_page' => $posts ) );
        while ( have_posts() ) : the_post();
    ?>
    <li>
         <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <div class="clear"></div>
    </li>
    <?php endwhile;
    }

    and here is the code of the tabber.php

    <?php if (get_theme_mod('tabber') == 'Yes') { ?>
    <div class="tabber">
        <ul id="tabs" class="tabs">
            <li><a href="#news" rel="news" class="selected"><?php _e('News', 'themejunkie'); ?></a></li>
            <li><a href="#press-releases" rel="press-releases"><?php _e('Press', 'themejunkie'); ?></a></li>
            <li><a href="#events" rel="events"><?php _e('Events', 'themejunkie'); ?></a></li>
        </ul>
        <div class="clear"></div>
        <ul id="news" class="tabcontent">
        <h2><center><b><a href="<?php bloginfo('url'); ?>/news/">Click Here To See More About Us In The News!</a></b></center></h2>
        <br />
        <?php tj_tabs_news(); ?>
        </ul>
        <ul id="press-releases" class="tabcontent">
        <h2><center><b><a href="<?php bloginfo('url'); ?>/press-releases/">Click Here To See What's Coming Up!</a></b></center></h2>
        <br />
        <?php tj_tabs_press(); ?>
        </ul>
        <ul id="events" class="tabcontent">
        <h2><center><b><a href="<?php bloginfo('url'); ?>/events/">Click Here To See What's Coming Up!</a></b></center></h2>
        <br />
        <?php tj_tabs_events(); ?>
        </ul>
    <script type="text/javascript">
        var tabs=new ddtabcontent("tabs")
        tabs.setpersist(false)
        tabs.setselectedClassTarget("link")
        tabs.init()
        </script>
    </div> <!--end: tabber-->
    <div class="clear"></div>
    <?php } ?>

    When I view the tabber, the first tab list the custom post of that type as hyperlinks. The remaining two tabs do not show the posts of their type. I can navigate to the archive pages and see posts listed, but not in my tabber.

    Where did I go wrong?

    Thanks for any help you can give!

Topic Closed

This topic has been closed to new replies.

About this Topic