...

View Full Version : List Category IDs???



swedy13
01-16-2012, 07:31 PM
Here is the page (http://www.zoiology.com/category/blog/guides/) I'm trying to fix. I would like to change the code so that it only gathers specific category IDs rather than every category.

Here is the code for that page:

<div id="colFull">
<?php
$current = get_the_category();
$current_id= $current[0] ->cat_ID;
$categs_list = get_category_parents($current_id);
$pieces = explode("/", $categs_list);
$category_name = strtolower($pieces[0]);
$categs = get_cat_id($category_name);
?>

<?php if(is_category() && in_category($current_id) || post_is_in_descendant_category($current_id)){?>
<h5><?php single_cat_title(); ?></h5>
<ul class="portfolioCategs">
<li><a href="<?php echo get_category_link(get_option('boldy_portfolio'))?>">All Guides</a></li>
<?php
$categories = get_categories('hide_empty=1&child_of='.$categs);
foreach ($categories as $cat) {
echo ('<li><a href="');
echo (get_category_link($cat->cat_ID).'">'.$cat->cat_name.'</a></li>');
}
?>
</ul>
<?php } ?>

And here is a list of the category IDs I want to include: 6,7,8,9,10,11,12,13,16

I tried solving the problem with the little coding help I received for my other list, but every time it goes to a blank page. Thanks so much for the help!!!

mlseim
01-16-2012, 08:23 PM
I thought I answered this post before ...
Was I the one that gave you bad info ... where it didn't work?
Let me know, and maybe we can try something else.

The blank page means you have a scripting error and your
error reporting is turned off. So it just displays "nothing".

EDIT:
So it was you that asked this before:
http://www.codingforums.com/showthread.php?t=248780

Please only post your questions/problems one time.
If what I gave you didn't work, you should have let me know.

Can you post what you tried ... the one that gave you a blank page?



.

swedy13
01-16-2012, 08:38 PM
This is a new problem.

The solution you provided last time worked, but only on my blog. Apparently the "Guides" section has a different line of code. It makes the categories appear on top of a portfolio section and uses different script.

I tried to adapt your code to work on the page, but I just don't know enough about it to make it work. I was able to substitute the right columned categories in for horizontal bar, but it just looked tacky so I decided I'd ask for help again.

I've been attempting to modify/substitute this line of code:

<?php echo get_cat_name(get_option('boldy_blog'));?>

and this line:

<ul >
<?wp_list_categories('include=6,7,8,9,10,11,12,13,16&title_li=');?>
</ul>

to replace different parts in this:

<?php
$current = get_the_category();
$current_id= $current[0] ->cat_ID;
$categs_list = get_category_parents($current_id);
$pieces = explode("/", $categs_list);
$category_name = strtolower($pieces[0]);
$categs = get_cat_id($category_name);
?>

Unfortunately, it just hasn't worked and my coding knowledge is non-existent so I'm not even sure if I'm modifying the right code, let alone what I'm doing wrong.

swedy13
01-16-2012, 09:11 PM
Holy crap! Guess that saying about even blind squirrels finding nuts is true. I added:


$categories = get_categories('exclude=1,4,48,49,54=');

to...


<?php
$categories = get_categories('hide_empty=1&child_of='.$categs);
foreach ($categories as $cat) {
echo ('<li><a href="');
echo (get_category_link($cat->cat_ID).'">'.$cat->cat_name.'</a></li>');
}
?>

and shockingly it worked! Thanks for the CODEX pages and sorry for all the simple questions. I'm learning :)

mlseim
01-16-2012, 09:59 PM
No problem ... glad you got it working.

WP has so many CODEX mashups, hacks, and other cool things to do.
And remember to only make changes to your theme files. Because if you
change any of the other WP files, they will be overwritten when you do
a revision upgrade.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum