carl-johan
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Show subcategories only for selected categorygkMotion:
Thanks for taking an interest in this!
The “use_desc_for_title” is not really what I’m looking for. What it does is it outputs the Category Description as the title of the link, i.e. the text that shows up in a little box when you hover the link.
What I’m looking for is a way to output the description instead of the name of the Category as the actual link to that specific category.MichaelH here on the forum has helped me out a bit with this.
His code does the trick I’m looking for, but only while in a Top Category, it returns nothing while in a sub-category.<?php $cat = get_query_var('cat'); $categories=get_categories('child_of='.$cat); if ($categories) { foreach($categories as $term) { echo '<a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View %s" ), $term->description ) . '" ' . '>' . $term->description.'</a>'; } } ?>
Any ideas are highly appreciated!
Thanks again!Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionHey again, Michael, I found this topic, basically discussing what I was looking for and found a solution too:
<?php
if (is_category()) {
$this_category = get_category($cat);
}
if($this_category->category_parent)
$this_category = wp_list_categories(‘orderby=id&title_li=&child_of=’.$this_category->category_parent.”&echo=0″); else
$this_category = wp_list_categories(‘orderby=id&title_li=&child_of=’.$this_category->cat_ID.”&echo=0″);
if ($this_category) { ?>-
<?php echo $this_category; ?>
<?php } ?>
This code displays the right categories on the right page, though I’m back to the Category Names and not description. If you see an easy solution for that, please let me know, otherwise take care!
Forum: Fixing WordPress
In reply to: Show subcategories only for selected categoryKarl19 –
<?php
if (is_category()) {
$this_category = get_category($cat);
}
if($this_category->category_parent)
$this_category = wp_list_categories(‘orderby=id&title_li=&child_of=’.$this_category->category_parent.”&echo=0″); else
$this_category = wp_list_categories(‘orderby=id&title_li=&child_of=’.$this_category->cat_ID.”&echo=0″);
if ($this_category) { ?>-
<?php echo $this_category; ?>
<?php } ?>
Thank you so much! This works fine for me, I’ve been looking all over for something like this.
Does anyone have an idea on how to tweak that code to display the Category Descriptions instead of the Name?
Forum: Plugins
In reply to: List subcategories if viewing a Category, and brothers if in subcat.Did anyone solve this and made it work. What would the full code be? I’m confused regarding this:
instead of using $parent = get_category($cat->category_parent);
try
$category_obj = get_category($cat);
$parent = $category_obj -> category_parent;
$parent_obj = get_category($parent);the result will be
$cat is set to the current categories id (magically)
$parent will be set to the parents idyou may or not need $parent_obj
Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionYeah man, sorry for all your trouble. I’m so grateful that your taking time to help me. I’ve been working hard, testing a lot of different stuff from the code you’ve given.
The last one you wrote seem to work nicely, and I could actually replaced my old is_category(yadiyada) with only your new one. Though it still won’t display any children of the parent when in a sub-category. I tried putting in something like echo ‘Sub-Category’; but it wouldn’t return that either, though I’ve might put it in the wrong place.
Anyway, I understand if you have more important issues to attend to than this, so thanks for all your help, and I’ll see if I can figure this out on my own.
Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionI would like “else” part to say, in plain english:
If the page displays any sub-category, then display the children of the parent category with the category description.
I.e. display the currently active child as well as the other children of the same parent.Does that make any sense?
Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionHaha, yeah it’s been a long way, let’s see if I can sum it up, I think the way there will be clear one’s the goal is..
You’ve helped me to list the descriptions of a category’s sub-category’s while on a category page. Each description links to that sub-category, so far it’s pretty straight forward right?
The last issue is that ones you click on a sub-category’s description, you go to that sub-category and then the list of descriptions disappear.
I’d like the same list of descriptions that appears on the category page to appear on the sub-category.Here’s the part of my sidebar.php that isn’t working, maybe it’ll make it more clear to you.
Thanks again for taking your time!
<div id="left_column"> [...] <div id="menu"> <ul> <?php /* If this page displays an Author Archive */ if ( is_author() ) { ?> <?php if(isset($_GET['author_name'])) : $curauth = get_userdatabylogin($author_name); // NOTE: 2.0 bug requires get_userdatabylogin(get_the_author_login()); else : $curauth = get_userdata(intval($author)); endif; ?> <h2 class="menu_header"><?php echo $curauth->display_name; ?></h2> <?php echo $curauth->user_email; ?> <?php echo $curauth->jabber; ?> <?php echo $curauth->description; ?> <? } /* If this page displays a Parent Category */ elseif ( is_category(illustration) || is_category(graphics-design) || is_category(photo) || is_category(styling) || is_category(pattern) ) { ?> <h2 class="menu_header">Lula Members</h2> <?php $cat = get_query_var('cat'); $categories=get_categories('child_of='.$cat); if ($categories) { foreach($categories as $term) { echo '<a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View %s" ), $term->description ) . '" ' . '>' . $term->description.'</a>'; } } ?> <? } /* If this page displays any other Category */ elseif ( is_category() ) { ?> <h2 class="menu_header">Lula Members</h2> <?php $cat = get_query_var('cat'); $categories=get_categories('child_of='.$cat); if ($categories) { foreach($categories as $term->parent) { echo '<a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View %s" ), $term->description ) . '" ' . '>' . $term->description.'</a>'; } } ?> <? } else { ?> <h2 class="menu_header">Lula Members</h2> <?php wp_list_authors('show_fullname=1&optioncount=0&exclude_admin=1'); ?> <?php } ?> [...] </ul> </div>
Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionWhere would that go in the code?
<?php $cat = get_query_var('cat'); $categories=get_categories('child_of='.$cat); if ($categories) { foreach($categories as $term) { echo '<a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View %s" ), $term->description ) . '" ' . '>' . $term->description.'</a>'; } } ?>
Sorry, but this is not my bag of crisps.
Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionThat would probably solve things, but I can’t get the sub-category to use that line of code. I have this in my sidebar.php:
<? } /* If this page displays a Parent Category */ elseif ( is_category(illustration) || is_category(graphics-design) || is_category(photo) || is_category(styling) || is_category(pattern) ) { ?>
and tried to use just elseif ( is_category() ) for any other category (i.e. all the sub-categories) but the sub-categories still go by the first category code.
I even tried calling the exakt sub-category ID with elseif ( is_category(’10’) ) but it still uses the top category code.
I don’t think there is a is_subcategory but there must be another way? Or will I have to make a template for each and every sub-category?
Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionOh, that’s not really it.
What I’m trying to get at is having a list of all sub-category descriptions, just as it is now on the category pages, on the sub-category pages as well.
Say I have a category called “Illustration” and sub-categories to that called say “Freelance” and “Commissioned Work”, then I’d like the menu to look like this, while on the Freelance category page.Illustration
-
Freelance
Commissioned WorkDisplaying the Parent Category, as well as displaying all children of the Parent Category, not children of the active sub-category, since it has no children.
I think what is needed is an alteration of the
$cat = get_query_var(‘cat’);
so that it calls for something like:
$cat = get_query_var(‘parent_cat’);
though that is probably not the least correct.I wish I could show you, but since the site is up and running, I don’t want to mess with it too much at this hour (it’s 14:45 in Sweden right now).
Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionI’m not sure if that was really clear what I just wrote, let me try to illustrate it:
The way it works now:
Active Category
Sub-Category 1
Sub-Category 2
Sub-Category 3Category
…empty…The way I’d like it to work:
Active Category
Sub-Category 1
Sub-Category 2
Sub-Category 3Parent Category
Sub-Category 1
Active Sub-Category 2
Sub-Category 3Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionYes! That worked, thank you so much Michael, you saved my day/week/life!
If you would help me with this last thing I would be ever thankful, but please do not feel obliged to do so.
The code I finished with is this, and it works like a charm in the top categories;
<?php $cat = get_query_var('cat'); $categories=get_categories('child_of='.$cat); if ($categories) { foreach($categories as $term) { echo '<a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View %s" ), $term->description ) . '" ' . '>' . $term->description.'</a>'; } } ?>
Though the list is empty on sub-categories, I guess since it’s calling for children to the active sub-category.
Is it possible to edit the code to work on sub-categories as well, i.e. get the same list of links while on a sub-category page as on the top category page?Forum: Plugins
In reply to: Have wp_list_categories output the category descriptionThanks a lot Michael, it worked almost all the way. I converted the code to this:
<?php $cat = get_query_var('cat'); $categories=get_categories('child_of='.$cat); if ($categories) { foreach($categories as $term) { echo '<a href="' . get_term_link( $term->term_id, $taxonomy ) . '" title="' . sprintf( __( "View %s" ), $term->description ) . '" ' . '>' . $term->description.'</a>'; } } ?>
The output works fine, but it links to this:
https://www.lula.se/?taxonomy=&term=
which seem to just return my “home.php” template.The link should go to this page:
https://www.lula.se/category/illustration/carl-johan-lindqvist-illustrationwhich is:
https://www.homesite.se/category-base/category-name/sub-category-nameAny ideas?
Thanks again for the help!
Forum: Fixing WordPress
In reply to: Passing Cat IDGreat man, exactly what is was looking for!
Anyone has any ideas?