• Hi.

    About 3 years ago I did a site in wordpress for a client. The site was compromised recently and I performed an upgrade.

    It has been so long since I worked with the site that I barely remember what I did. However, it appears I was using the plug in My Category Order in conjunction with some code and it worked fine in 2.0.1. I am quite the php newbie and rusty to boot, but perhaps someone can help me?

    What I am trying to do is to get the subcategories on a particular category page to list in a particular order (cat 26 and subcats 27 & 29-33 [there is no subcat 28]}. First I had the subcat names listed as anchored links and then they were listed in the particular order below.

    The code that worked in 2.0.1 but does not work in 2.8 is here:

    <?php
    	//If there's no catID coming in on the query string, default to 0
    	if ($cat == "") { $cat = 0; }
    	//pull categories straight from the db using the order specified by the My Category Order plugin
    	$results=$wpdb->get_results("SELECT * FROM $wpdb->categories WHERE category_parent = $cat and category_count != 0 ORDER BY cat_my_order ASC");
    
    	if($results)
    
    	foreach($results as $row)
    	{
    		//create cats array like below, just this time in the order we want
    		$cats[$row->cat_ID] = $row->cat_name;
    	}
    	$catCount = count($cats);
    /* start of The Loop, Display by Category style */
        if (have_posts() && $catCount != 0) :
    ?>
    
    <?php
    /* collect categories */
    
            //foreach($posts as $post) :
            //    $category = get_the_category();
            //    $cats[$category[0]->cat_ID] = $category[0]->cat_name;
            //endforeach;
    
    /* uncomment next line to have categories sort alphabetically */
    //uasort($cats, strcasecmp);
    
        $cats = array_flip($cats);
    ?>
    <div class="directory">
    <?php
    /* displays category anchor link 'navigation bar' */
        foreach($cats as $current_cat) :
    ?>
        <?php if($first) { echo ' | '; } $first++; ?><a href="#cat-<?php echo trim($current_cat); ?>"><?php echo get_the_category_by_id(trim($current_cat)); ?></a>
    <?php endforeach; ?>
        </div>
    	<br /><br />
    
    <?php
    /* start of 'display by category' loop */
        foreach($cats as $current_cat) :
    ?>
            <h5 id="cat-<?php echo trim($current_cat); ?>"><a href="<?php echo get_category_link(trim($current_cat)); ?>" title="View all posts in <?php echo get_the_category_by_id(trim($current_cat)); ?>"><?php echo get_the_category_by_id(trim($current_cat)); ?></a></h5>
    <?php
    /* post loop for each category listing */
            foreach($posts as $post) :
                the_post();
                $category = get_the_category();
                if($current_cat == $category[0]->cat_ID) : // if post is in correct category
    ?>
                <div class="post" id="post-<?php the_ID(); ?>">
                    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    <!--- uncomment below to add post date -->
     <!---<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>  -->
    
                    <div class="entry">
                        <?php the_content('Read the rest of this entry &raquo;'); ?>
                    </div>
                </div>
    <?php
                endif; // end 'if post in correct category'
            endforeach; // end post loop
    echo "<h6><a href=\"#top\">[ back to top ]</a></h6>";
            rewind_posts(); // reset loop for next category
        endforeach; // end 'display by category' loop
    ?>

    Any help/correction/advice is greatly appreciated

Viewing 1 replies (of 1 total)
  • Thread Starter ritalcnyc

    (@ritalcnyc)

    Hi. Okay, this was a ridiculous post, I know…I was so frustrated I wasn’t being clear, I didn’t give the thing much thought, didn’t consider disabling a plug in that didn’t work, so let’s go to square one.

    So…I found the lovely post https://www.ads-software.com/support/topic/38046?replies=52 which allowed you to post by category on the home page and modified it for my category page, but I am only seeing one subcategory when I use the code on my category-xx.php page. Is this because I am dealing with subcategories? What I would like is the same as what is shown on this page but with the children of the category?

    What I need is for all my sub category/children to post under the category page much with a similar result as what is shown on the https://www.ads-software.com/support/topic/38046?replies=52 page.

Viewing 1 replies (of 1 total)
  • The topic ‘WordPress Upgrade from 2.0.1 to 2.8 and category template not working’ is closed to new replies.