WordPress.org

Ready to get started?Download WordPress

Forums

Press, News, Events
[resolved] Cannot Create Lists of Posts (3 posts)

  1. kirkward
    Member
    Posted 1 year ago #

    I am coding a "tabber" in the sidebar. The tabber has three tabs, one for each custom post type created by the plugin. I cannot get the tabber to list the press and events posts. Here is what one of my advisors gave me ...

    (1) Added to theme functions

    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;
    }

    Code in the tabber sidebar ...

    <?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" rel="press"><?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" class="tabcontent">
        <h2><center><b><a href="<?php bloginfo('url'); ?>/press/">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 } ?>

    Can you tell us what we did wrong in trying to list the press-releases and events posts?

    http://wordpress.org/extend/plugins/press-news-events/

  2. kirkward
    Member
    Posted 1 year ago #

    Solved

    The developers of this plugin were inconsistent in their naming. Their slug shows the types all as plural press-releases, news and events. while the actual post type is hidden away inside and the only post type that is plural is news.

    Caused a lot of heartache wasting three and a half days trying to figure out why I could not list the posts in all three types. I am a non-coder and only discovered the difference by accident.

    Not sure it can be called sloppy coding, but I do know it was frustrating.

  3. rafaelfaria
    Member
    Posted 1 year ago #

    I did a quick shortcode to display on my homepage:

    in the custom-post-type.php constructor i added:

    add_shortcode($this->slug, array($this, 'plugin_shortcode') );

    Than i created 2 other functions

    function plugin_shortcode($atts) {

    $file = get_stylesheet_directory(). "/home/".$this->slug.".php";

    if ( !file_exists( $file ) )
    return false;

    $args = array(
    'post_type' => $this->slug,
    'post_status' => 'publish',
    'posts_per_page' => is_numeric($atts['count']) ? $atts['count'] : 5,
    'order' => 'DESC'
    );
    $posts = query_posts($args);
    wp_reset_query();

    $items = Array();
    $pne = 'press-news-events';

    foreach($posts as $k => $item) {

    $link = get_permalink($item->ID);

    $date = get_post_meta($item->ID, '_date', true);

    $item->day = date_i18n(__('d', $pne), $date);
    $item->month = date_i18n(__('M', $pne), $date);
    $item->year = date_i18n(__('Y', $pne), $date);
    $item->title = $item->post_title;
    $item->link = (strpos($link, 'http://') !== false) ? $link : "http://{$link}";

    $items[$k] = $item;
    }

    return $this->render_template($file, $items);
    }

    function render_template($template, $data){

    if ( !file_exists( $template ))
    return;

    ob_start();
    include($template);
    $html = ob_get_clean();
    return $html;
    }

    than all i had to do was call like:

    [news count=10]

    or [events count=10]

    and it would get the template from a folder called "home" in my themes and display the html. :)

    hope it helps.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.