Page-main has 4 posts from category-two as its sidebar. Now when I click on any of the post under category-two , its takes to me that post but the sidebar shows posts from other categories.
how is this done at the moment?
is that hardcoded into sidebar.php?
or a widget?
default widget or from a plugin?
———-
I had hacked the ‘category-posts’ plugin a while ago – this might be a starting point for your code: http://wordpress.org/support/topic/show-posts-of-current-category?replies=10
(it might not work on the front page or in achives – but there should be a way to fix it.)
Hey Alchymyth
Currently its not done. I am just finding a way to do. It can be a sidebar / widget / plugin. So let me look into your ‘category-posts’ plugin.
I will try uploading the site too so that you can get a preview of what exactly I am talking about.
And Thanx once again mate.
<?php if (is_single(array('815','817','813','819'))) { ?>
<?php
global $post;
$args = array( 'numberposts' => 20, 'category' => 109 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li>
<span class="sidebar-link"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></span></li>
<?php endforeach; ?>
<?php } elseif (is_single(array('852','850','848','846','844','842','840','838','836','834','829'))) { ?>
<?php
global $post;
$args = array( 'numberposts' => 20, 'category' => 108 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li>
<span class="sidebar-link"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></span></li>
<?php endforeach; ?>
<?php } else { ?>
<?php wp_list_categories() ?>
<?php } ?>
Phew ! This is working as of now. Any good suggestions to reduce or clean up the code ?
Instead of array, Can we use a RANGE parameter ?
has 4 posts from category-two as its sidebar
have you tried to work with:
<?php if( is_single() && in_category('category-two') ) { ?>
http://codex.wordpress.org/Function_Reference/in_category
there is no hint in the codex, that using RANGE would work – however, you can try it.