Support » Plugins and Hacks » Hacks » [Resolved] Combining two small scripts

[Resolved] Combining two small scripts

  • Hi there –

    I have two working scripts that I would like to combine into one.

    This one prevents posts in subcats from displaying on top-level category archive:

    <br />
    <?php<br />
    if ( is_category() ) {<br />
      $cat = get_query_var('cat');<br />
      query_posts(array('category__in' => array($cat)));<br />
    }<br />
    ?><br />

    And this one alphabetizes the posts:

    <br />
    <?php if (is_category())<br />
    { $posts = query_posts($query_string . '&orderby=title&order=asc'); } ?><br />

    I can get either one of these working at a time, but not both together. Is there any way to combine them?


    [ Moderator note: your other post was deleted as duplicates or topics that point to other topics is not helpful. The forum you were using was fine BTW. ]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,
    You can try:

    if ( is_category() ) {
      $cat = get_query_var('cat');
      query_posts( array( 'category__in' => array($cat), 'orderby' => 'title', 'order' => 'ASC' ) );

    Hi –

    Thank you. That does work for the alphabetizing and hiding, but it does something weird to the pages: the first 10 posts are listed correctly, but then when I click the next button, it lists the same 10 posts on page 2 and all subsequent pages.

    You need the page argument too:

    if ( is_category() ) {
      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
      $cat = get_query_var('cat');
      query_posts( array(
      	'category__in' => array($cat),
      	'orderby' => 'title',
      	'order' => 'ASC',
      	'posts_per_page' => 10,
      	'paged' => $paged

    Hmm, no. It’s still alphabetized, but it stopped hiding subcats, plus it printed your code at the top of the page.

    If it printed my code, I think that’s because you did a copy/paste and not enclosed the code in <?php …… ?>

    Oops, you’re right.

    That did it – everything is working now exactly like I want it to. Thank you!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Combining two small scripts’ is closed to new replies.