If I wanted to echo the current category_description using these functions: as it stands, if I do something like this it only shows the earliest category created. {?php elsecategories())?} {?php echo category_description(); ?} {?php endif; ?} If I add a while loop, it shows all the category_descriptions. I onlyb want to show the CURRENT description of the page. Here are your functions: categories() Loops through every category, one by one. Returns true when there is more categories to be listed or false when we are at the end. Should be used like this: {?php while(categories()): ?} <!-- Loop through the categories. --> {?php endwhile; ?} category_count Returns the number of posts that are in the current category. category_description Returns the current category description. category_id Returns the current category ID. category_slug Returns the current category url slug. category_title Returns the current category title. category_url Returns the full current category url. total_categories Returns the number of categories.
Not sure I made it clear, but what I am trying to do is to correctly identify the category_description for each page using the functions I listed. just echoing the function category_description doesn't work, as it appears to only see the first category I created. Somehow I need to collect the category_ids and attach them to the category_descriptions prior to echoing the output, if that makes sense.
I think you need the id from the page GET or POST to compare the category with. categories seems to return all the categories, not just the current one. So, it's probably something like this: {?php while(categories()){ if (category_id == _GET['id'] || category_id == _POST['id']) { echo category_description; break; } } ?}
Sorry... I've been working on ruby for a while.. it's $_GET['id'] and $_POST['id'] . Note the $ for variables. Also.. id might not be the name of the id.. it could product_id or category_id . Usually you can tell on your url string. If it says http://www.xxx.com?category_id=2&widget=3 or something similar, it's category_id, i.e. $_GET['category_id']
also.. it's category_id() note the () for functions. I've been using ruby for too long it's got none of those syntax. Anothe note: in instuctions with iterators, current doesn't mean current page.. it' means the current iterator position. So: while(categories()){ if (category_id() == _GET['id'] || category_id() == _POST['id']) { echo category_description; break; } }
yeah, i fixed it the way you said, but it can't find the array: 'id' or category_id either. When I look into the phpmyadmin, the actual database entry is anchor_categories and there is an id in the table. However, anchor doesn't actually use the actual database table name, rather it has a function system. {?php /** * Theme functions for categories */ function total_categories() { if( ! $categories = Registry::get('categories')) { $categories = Category::get(); $categories = new Items($categories); Registry::set('categories', $categories); } return $categories->length(); } // loop categories function categories() { if( ! total_categories()) return false; $items = Registry::get('categories'); if($result = $items->valid()) { // register single category Registry::set('category', $items->current()); // move to next $items->next(); } return $result; } // single categories function category_id() { return Registry:rop('category', 'id'); } function category_title() { return Registry:rop('category', 'title'); } function category_slug() { return Registry:rop('category', 'slug'); } function category_description() { return Registry:rop('category', 'description'); } function category_url() { return base_url('category/' . category_slug()); } function category_count() { return Query::table(Base::table('posts')) ->where('category', '=', category_id()) ->where('status', '=', 'published')->count(); }
Okay... categories is doing what I expected it to do. It iterates through a static class and returns ALL of the categories one by one. So, you need to know which category the web page is currently showing. Can you put this line of code and paste the results : foreach ($_POST as $param_name => $param_val) { echo "Param: $param_name; Value: $param_val ,"; } foreach ($_GET as $param_name => $param_val) { echo "Param: $param_name; Value: $param_val ,"; } put this on the page you want to edit