• Resolved jimmytubbs

    (@jimmytubbs)


    <?php
    /*
    Template Name: news
    */
    include"header2.php";
    include"sidebar.php";
    ?>
    <div id=pagetitle><img src=https://www.*****/*****/arrowsmallpurple1.png /><strong><?php the_title();?></strong></div><br />
    
    <div id=maincontent>
    <?php
    if (is_page('2') ) {
    $cat = array(1,2,3,4,5,6,7,8,9,10,11);
    } elseif ( is_page('3') ) {
    $cat = array(7,);
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       );
    $my_query = new WP_Query($args); 
    
    ?>
    
    <?php if( $my_query->have_posts() ) : ?>
    
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    			?>
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <div id=news><h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2></a></div>
    <?php the_excerpt(); ?>
     <h4><span id=news>Written by <?php the_author();?> at <?php the_time();?> <a class="title" href="<?php the_permalink() ?>" rel="bookmark">Read More.... &nbsp; &nbsp <?php comments_number(); ?></a> </span></h4>
    <?php endwhile; else: ?>
    <div id=footerbg">
    			<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    		</div>
    
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>
    </div>
    </div></div>
    <?php
    include"footer.php";
    ?>

    This is a template for a WP page and it wont show my catagories for which i want it to…..

Viewing 2 replies - 1 through 2 (of 2 total)
  • Sure you got the right category ids or page ids.

    Put this after your include sidebar to check if you’ve got the right page

    echo "<pre>"; print_r($wp_query->query_vars); echo "</pre>";

    Also install the Reveal Admin IDs to make sure you’ve bot the correct ids:
    https://www.ads-software.com/extend/plugins/reveal-ids-for-wp-admin-25/

    Thread Starter jimmytubbs

    (@jimmytubbs)

    Still doesn’t like it,it comes out on the id 315 page as no posts in your criteria when there is, ive got the correct id’s as i used the plugin that you said.
    this is my curent version of the code

    <?php
    /*
    Template Name: news
    */
    include"header2.php";
    include"sidebar.php";
    
    ?>
    <div id=pagetitle><img src=https://www.******/*****/arrowsmallpurple1.png /><strong><?php the_title();?></strong></div><br />
    
    <div id=maincontent>
    <?php
    if (is_page('147') ) {
    $cat = array(1,15,55,35,19,16,17,14,13,18,20);
    } elseif ( is_page('315') ) {
    $cat = array(17);
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       );
    $my_query = new WP_Query($args); 
    
    ?>
    
    <?php if( $my_query->have_posts() ) : ?>
    
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    			?>
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <div id=news><h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2></a></div>
    <?php the_excerpt(); ?>
     <h4><span id=news>Written by <?php the_author();?> at <?php the_time();?> <a class="title" href="<?php the_permalink() ?>" rel="bookmark">Read More.... &nbsp; &nbsp <?php comments_number(); ?></a> </span></h4>
    <?php endwhile; else: ?>
    <div id=footerbg">
    			<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    		</div>
    
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>
    </div>
    </div></div>
    <?php
    include"footer.php";
    ?>

    in addition if this helps this is what
    echo "<pre>"; print_r($wp_query->query_vars); echo "</pre>";
    shows

    Array
    (
        [pagename] => news
        [error] =>
        [m] => 0
        [p] => 0
        [post_parent] =>
        [subpost] =>
        [subpost_id] =>
        [attachment] =>
        [attachment_id] => 0
        [name] => news
        [hour] =>
        [static] =>
        [page_id] => 0
        [second] =>
        [minute] =>
        [day] => 0
        [monthnum] => 0
        [year] => 0
        [w] => 0
        [category_name] =>
        [tag] =>
        [cat] =>
        [tag_id] =>
        [author_name] =>
        [feed] =>
        [tb] =>
        [paged] =>
        [comments_popup] =>
        [meta_key] =>
        [meta_value] =>
        [preview] =>
        [category__in] => Array
            (
            )
    
        [category__not_in] => Array
            (
            )
    
        [category__and] => Array
            (
            )
    
        [post__in] => Array
            (
            )
    
        [post__not_in] => Array
            (
            )
    
        [tag__in] => Array
            (
            )
    
        [tag__not_in] => Array
            (
            )
    
        [tag__and] => Array
            (
            )
    
        [tag_slug__in] => Array
            (
            )
    
        [tag_slug__and] => Array
            (
            )
    
        [caller_get_posts] =>
        [suppress_filters] =>
        [post_type] => post
        [posts_per_page] => 6
        [nopaging] =>
        [comments_per_page] => 50
        [order] => DESC
        [orderby] => wp_posts.post_date DESC
    )

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Won’t show certain catagories’ is closed to new replies.