WordPress.org

Ready to get started?Download WordPress

Forums

Help- want select category posts on static page! (13 posts)

  1. pdhaudio83
    Member
    Posted 5 years ago #

    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

  2. s_ha_dum
    Member
    Posted 5 years ago #

    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'.

  3. pdhaudio83
    Member
    Posted 5 years ago #

    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.

  4. pdhaudio83
    Member
    Posted 5 years ago #

    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();?>
  5. pdhaudio83
    Member
    Posted 5 years ago #

    anyone?

  6. s_ha_dum
    Member
    Posted 5 years ago #

    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.

  7. pdhaudio83
    Member
    Posted 5 years ago #

    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...?

  8. s_ha_dum
    Member
    Posted 5 years ago #

    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.

  9. pdhaudio83
    Member
    Posted 5 years ago #

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

  10. pdhaudio83
    Member
    Posted 5 years ago #

    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

  11. pdhaudio83
    Member
    Posted 5 years ago #

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

    Also, here are the posts in the category:

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

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

  12. s_ha_dum
    Member
    Posted 5 years ago #

    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?

  13. pdhaudio83
    Member
    Posted 5 years ago #

    I don't understand what you're asking?

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

Topic Closed

This topic has been closed to new replies.

About this Topic