• Hi guys. I’ve been searching up and down and need some help with code. I’m a noob.

    What I want to do is use the main index for all category postings except one. I used the Category excluder to hide the one category. The category that is hidden on the main page I want to show up on a static page so that only people who click a “news” link see the “news” posts.

    Seems I need a php code, and the ones I’ve found in support topics don’t work. Some sort of template to fix this? I’ve tried a ton.

    The category ID is 73.

    Help is greatly appreciated.
    blog @ TheGasGame.com

Viewing 12 replies - 1 through 12 (of 12 total)
  • Add <?php query_posts("cat=73"); ?> to your page before the loop starts. Exactly this problem is solved on the Codex page for query_posts, under the heading ‘Show One Category by ID’.

    Thread Starter pdhaudio83

    (@pdhaudio83)

    For the page, I need to use a custom template too it seems?

    I’m slowly figuring it out, but I don’t have a “factory” template that will work. The archive template displays “Archive News Category” on the top, the index.php template simply produces a “next” link with no content, and the page.php template produces the first page correctly, but the second page is a duplicate.

    Can anyone quick throw the code together for the complete template that would show all posts for that category? I’d really appreciate it- I’ve been toying with this for 3 days now.

    Thread Starter pdhaudio83

    (@pdhaudio83)

    Here’s what I have, but for some reason its showing only 5 posts in that category even though there are 11. If I hit “NEXT” button on the bottom, it WILL go to a second page, but the posts are the SAME as page #1…

    please help!

    <?php /* Template Name: News
    */ ?>
    
    <?php get_header();?>
    
    		<div id="content">
    			<!-- primary content start -->
    <?php genki_announcement() ?>
    <?php $posts = query_posts('showposts');?>
    <?php if ($posts) {
            if ( get_settings('aquafluid_asideid')!='') $AsideId = get_settings('aquafluid_asideid'); query_posts('cat=73');
    
    				function stupid_hack($str)
    				{
    					return preg_replace('|</ul>\s*<ul class="asides">|', '', $str);
    				}
    				ob_start('stupid_hack');
    				foreach($posts as $post)
    				{
    					the_post();
    				?>
    
    <?php if ( in_category($AsideId) && !is_single() ) : ?>
    					<ul class="asides">
    						<li id="p<?php the_ID(); ?>">
    							<?php echo wptexturize($post->post_content); ?>
    							<br />
    							<?php comments_popup_link('(0)', '(1)','(%)')?>  | <a href="<?php the_permalink(); ?>" title="Permalink: <?php echo wptexturize(strip_tags(stripslashes($post->post_title), '')); ?>" rel="bookmark">#</a> <?php edit_post_link('(edit)'); ?>
    						</li>
    					</ul>
    				<?php else: // If it's a regular post or a permalink page ?>
    					<div class="post" id="post-<?php the_ID(); ?>">
    						<h2 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <p class="post-info">
    							<b><span class="post-comments"><?php comments_popup_link('0 comments', '1 comment', '% comments','','comments off'); ?></b></span>
    							<b><em class="date"><?php the_time('l d M Y'); ?></em></b> | Posted By
    							<em class="user"><?php the_author_posts_link() ?></em> |
    							<em class="cat"><?php the_category(', ') ?></em> <?php edit_post_link(); ?>
              <div class="post-content"></div>
    							<?php the_content('Continue Reading »'); ?>
    							<?php wp_link_pages();?>
                  <p class="post-tags">
                    <?php if (function_exists('the_tags')) the_tags('Tags: ', ', ', '<br />'); ?>
                  </p><a class="yaction-link-bookmark"></a>
    <a class="yaction-link-send"></a>
    <a class="yaction-link-blog"></a>
    <a class="yaction-link-print"></a>
    
                  <!--
    								<?php trackback_rdf(); ?>
    
    							-->
    						</div>
    
    					<?php endif; // end if in category ?>
    				<?php
    				}
    			} // end if (posts)
    			else
    			{
    				echo '<p>Sorry, No Posts matched your criteria.</p>';
    			}
    		?>
    		<p align="center"><?php posts_nav_link(' - ','« Prev','Next »') ?></p>
    		<!-- primary content end -->
    		</div>
    	<?php get_sidebar();?>
    <?php get_footer();?>
    Thread Starter pdhaudio83

    (@pdhaudio83)

    anyone?

    You have to call query_posts() before the Loop starts. You’ve called it once before the loop starts and once during the Loop, and you haven’t given ‘showposts’ a parameter value. Replace <?php $posts = query_posts('showposts');?> with <?php query_posts('showposts=-1&cat=73'); ?> and remove the other call to query_posts. You should get all posts for that category.

    Thread Starter pdhaudio83

    (@pdhaudio83)

    Thanks for the help.

    I’ve made changes, here’s the current code:

    <?php /* Template Name: News
    */ ?>
    
    <?php get_header();?>
    
    		<div id="content">
    <?php query_posts('showposts=-1&cat=73'); ?>
    			<!-- primary content start -->
    <?php genki_announcement() ?>
    
    <?php if ($posts) {
            if ( get_settings('aquafluid_asideid')!='') $AsideId = get_settings('aquafluid_asideid');
    				function stupid_hack($str)
    				{
    					return preg_replace('|</ul>\s*<ul class="asides">|', '', $str);
    				}
    				ob_start('stupid_hack');
    				foreach($posts as $post)
    				{
    					the_post();
    				?>
    
    <?php if ( in_category($AsideId) && !is_single() ) : ?>
    					<ul class="asides">
    						<li id="p<?php the_ID(); ?>">
    							<?php echo wptexturize($post->post_content); ?>
    							<br />
    							<?php comments_popup_link('(0)', '(1)','(%)')?>  | <a href="<?php the_permalink(); ?>" title="Permalink: <?php echo wptexturize(strip_tags(stripslashes($post->post_title), '')); ?>" rel="bookmark">#</a> <?php edit_post_link('(edit)'); ?>
    						</li>
    					</ul>
    				<?php else: // If it's a regular post or a permalink page ?>
    					<div class="post" id="post-<?php the_ID(); ?>">
    						<h2 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <p class="post-info">
    							<b><span class="post-comments"><?php comments_popup_link('0 comments', '1 comment', '% comments','','comments off'); ?></b></span>
    							<b><em class="date"><?php the_time('l d M Y'); ?></em></b> | Posted By
    							<em class="user"><?php the_author_posts_link() ?></em> |
    							<em class="cat"><?php the_category(', ') ?></em> <?php edit_post_link(); ?>
              <div class="post-content"></div>
    							<?php the_content('Continue Reading ?'); ?>
    							<?php wp_link_pages();?>
                  <p class="post-tags">
                    <?php if (function_exists('the_tags')) the_tags('Tags: ', ', ', '<br />'); ?>
                  </p><a class="yaction-link-bookmark"></a>
    <a class="yaction-link-send"></a>
    <a class="yaction-link-blog"></a>
    <a class="yaction-link-print"></a>
    
                  <!--
    								<?php trackback_rdf(); ?>
    
    							-->
    						</div>
    
    					<?php endif; // end if in category ?>
    				<?php
    				}
    			} // end if (posts)
    			else
    			{
    				echo '<p>Sorry, No Posts matched your criteria.</p>';
    			}
    		?>
    		<p align="center"><?php posts_nav_link(' - ','? Prev','Next ?') ?></p>
    		<!-- primary content end -->
    		</div>
    	<?php get_sidebar();?>
    <?php get_footer();?>

    Now the static page only displays the latest post in that category. I’ve played around with it and can’t get it… I’ve read through the codex a bit and am not understanding why it’s doing this.

    I feel like I’m almost there…?

    I don’t know why you are getting only one post. The code I posted works when I test it here. If I spot the problem I’ll let you know.

    Thread Starter pdhaudio83

    (@pdhaudio83)

    If it helps, view the page at thegasgame.com/news/ (it MAY be a private page)

    Thread Starter pdhaudio83

    (@pdhaudio83)

    Hmm- futhermore, when it should display a wordpress 404, it displays a wordpress 404 WITH a blog date of “unavailable”, etc.

    Oooops…Not found !

    As outputted by the Server on 17 Mar 2009 09:32 pm | Tagged as: Unavailable

    The Server can not find the page you are looking for.
    You may try to locate it yourself by doing a search or browsing through the archives

    Thread Starter pdhaudio83

    (@pdhaudio83)

    Just some follow-up, I made the page visible.

    Also, here are the posts in the category:

    https://www.thegasgame.com/category/news/

    so we know its not an issue of only having one post.

    So the page you posted is without the query_posts functions we’ve been trying to work out?

    What is the page that does have that function?

    Thread Starter pdhaudio83

    (@pdhaudio83)

    I don’t understand what you’re asking?

    I made the page template using the index.php file.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Help- want select category posts on static page!’ is closed to new replies.