Forums

[resolved] list all the entries under a specific category (8 posts)

  1. Stingraynut
    Member
    Posted 3 years ago #

    I would like to have a list of the posts under each category in the sidebar that will link to the actual entry. (rather than have ALL the posts for the category load inthe page)

    I've been searching everywhere with no luck, hope someone here can help me.

    I found a few suggestions about adding code to php pages, but there is no wp-list-categories file and there are TWO sidebar.php, one in Admin and one in the theme - I renamed them and nothing changed in the sidebar, I must have misunderstood how the system works.

  2. Maxaud
    Member
    Posted 3 years ago #

    try the below code (change the 123 to your category id and the 5 to how many posts you want to list):

    <?php $my_query = new WP_Query('cat=123&showposts=5'); ?>
    <ul>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<li>
    		<h5><a href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h5>
            		<p>Written: <?php the_time('F j, Y') ?>, By <strong><?php the_author_link(); ?></strong><br /></p>
    	</li>
    <?php endwhile; ?>
    </ul>
  3. nzde
    Member
    Posted 3 years ago #

    The "Latest Posts by Category Archive" might also be of interest: http://blogsessive.com/blogging-tools/wp-plugin-latest-posts-by-category-archive/

  4. Stingraynut
    Member
    Posted 3 years ago #

    Thanks very much for the quick replies.

    @nzde I've downloaded the plugin, thanks, thats it!! I would like to change the icon so that it sits to the left of the named category rather than at present halfway down the list for that category - I expect some CSS will fix that up. And I will change the Title back to just Categories and remove the existing Category box

    - I'll be working on the site for the next few hours so what you see will depend on what I've done.

    @maxaud thanks for the code, I'd like to try that too because I want to know more about whats under the hood in WordPress. Where do I put that code, ie what filename and whereabouts in the code?

  5. Maxaud
    Member
    Posted 3 years ago #

    I'll have to check the files exactly to add it to the sidebar but I have worked with the same theme that you're building off of.

    The site I did is here:
    http://www.gt4rc.com
    (my car is the black one)

    I'll get back to you with where you might want to start modifying

  6. Maxaud
    Member
    Posted 3 years ago #

    in sidebar.php it should read something like:

    <div id="sidebar">
    		<ul>
    			<?php 	/* Widgetized sidebar, if you have the plugin installed. */
    					if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    
    			<!-- Author information is disabled per default. Uncomment and fill in your details if you want to use it.
    			<li><h2>Author</h2>
    			<p>A little something about you, the author. Nothing lengthy, just an overview.</p>
    			</li>
    			-->
    
    			<?php wp_list_categories('show_count=1&amp;title_li=<h2>Categories</h2>'); ?>
    
    			<?php /* If this is the frontpage */ if ( is_home() || is_page() ) { ?>
    				<?php wp_list_bookmarks(); ?>
    			<?php } ?>
    				<li class="pagenav"><h2>Meta</h2>
    				<ul>
    					<?php wp_register(); ?>
    					<li><?php wp_loginout(); ?></li>
    					<li><a href="http://www.wpthemesfree.com/" title="WordPress Themes">WordPress Themes</a></li>
    					<?php wp_meta(); ?>
    				</ul>
    				</li>
    
    			<?php if ( is_404() || is_category() || is_day() || is_month() ||
    						is_year() || is_search() || is_paged() ) {
    			?> <li>
    
    			<?php /* If this is a 404 page */ if (is_404()) { ?>
    			<?php /* If this is a category archive */ } elseif (is_category()) { ?>
    			<p>You are currently browsing the archives for the <?php single_cat_title(''); ?> category.</p>
    
    			<?php /* If this is a yearly archive */ } elseif (is_day()) { ?>
    			<p>You are currently browsing the <a href="<?php bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives
    			for the day <?php the_time('l, F jS, Y'); ?>.</p>
    
    			<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    			<p>You are currently browsing the <a href="<?php bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives
    			for <?php the_time('F, Y'); ?>.</p>
    
    			<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    			<p>You are currently browsing the <a href="<?php bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives
    			for the year <?php the_time('Y'); ?>.</p>
    
    			<?php /* If this is a monthly archive */ } elseif (is_search()) { ?>
    			<p>You have searched the <a href="<?php echo bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives
    			for <strong>'<?php the_search_query(); ?>'</strong>. If you are unable to find anything in these search results, you can try one of these links.</p>
    
    			<?php /* If this is a monthly archive */ } elseif (isset($_GET['paged']) &amp;&amp; !empty($_GET['paged'])) { ?>
    			<p>You are currently browsing the <a href="<?php echo bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives.</p>
    
    			<?php } ?>
    
    			</li> <?php }?>            
    
    			<?php endif; ?>
    		</ul>
        </div><!-- end of sidebarwrapper -->
        <br class="fixfloat" />

    if you are using widgets, you will have to add the code after the endif; 4th line from the end if you want to show up.

    try adding this after the endif; :

    <li class="pagenav"><h2>Recent Category Posts</h2>
    <?php $my_query = new WP_Query('cat=123&amp;showposts=5'); ?>
    <ul>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<li>
    		<h5><a href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h5>
            		<p>Written: <?php the_time('F j, Y') ?>, By <strong><?php the_author_link(); ?></strong><br /></p>
    	</li>
    <?php endwhile; ?>
    </ul>
    </li>
  7. Stingraynut
    Member
    Posted 3 years ago #

    Thanks maxaud, much appreciated - I will have a play with that and see what happens - I'm ok with Css and html but don't have much PHP skills (yet) I think wordpress is going to fix that gap in my knowledge!!

    I would never have thought to insert AFTER the endif.

    I spent a long time today trying to make font of the 3 pages listed in the sidebar the same weight as the category titles, I was sure it was just a matter of making a CSS rule for the nested lists, but nothing I did targeted just the page titles. I'll work it out eventually

    You've done a great job with that Ferrari theme, I like the random cars in the header - is that a widget ?

    Is your car the black one showing side on, LH side?

    I'm going to set this topis as 'resolved'

  8. Maxaud
    Member
    Posted 3 years ago #

    You could put it before the endif; but it would show up if you had widgets in your sidebar.

    The header image just uses rand() php to get a different header image each time. My car is the only black one on the site.

Topic Closed

This topic has been closed to new replies.

About this Topic