Get the category name,permalink and description - php

So I need to list some categories, and I can list them with wp_list_categories but i also need the description for that category, i need to do something like this:
Category name
The description here
And right now I'm stuck i don't know how to do this with wordpress

This page shows how to add the Category Description: http://codex.wordpress.org/Function_Reference/category_description
It should have everything you need there, but for quick reference, the simplest way is:
<?php echo category_description(); ?>
(within the Wordpress loop)
EDIT
Just realized since you're combining this with wp_list_categories(), you'll have to create a loop that goes through the categoriy lists and displays the title and the description.
Try this Wordpress support page: http://wordpress.org/support/topic/have-wp_list_categories-output-the-category-descpription

Solved:
<?php
foreach(get_categories() as $category):
echo $category->cat_name;
echo category_description($category->cat_ID);
endforeach;
?>

Related

Get all image/attachment IDs in Wordpress

I want to dislay wordpress gallery in single.php. I put this code into single.php
<?php echo do_shortcode('[gallery columns="4" ids="1,2,3,4,5,6,7,8"]');?>
The problem is that image ids are changing based on post ID.
I wonder what code should I put? I did:
<?php
$id_image = what_code_should_i_put_here;
echo do_shortcode('[gallery columns="4" ids="'.$id_image.'"]');
?>
But I have no idea the code part.
what_code_should_i_put_here must result '1,2,3,4,5,6,7,8'
Did you check this one: https://wordpress.stackexchange.com/questions/149268/get-all-image-ids-from-the-media-library? After you get IDs array, you would simply need to convert it to delimited string. Let me know if you need help on that.

Adding a title attribute to category without affecting core

My current setup includes having the category of each post. But whenever I mouse over the category, it shows the default message of Show all posts in [category].
I have looked around and have seen some pretty similar questions that require multiple lines of php code. This surely cannot be that complicated. Is there a way I can perhaps tweak the following to get it to do what I want?
<?php the_category(' '); ?>
This is the code that returns the above. I am looking through the codex and found category_description() and get_the_category(). I am kind of new to arrays and am having problems figuring them out. I was kind of hoping that something like this would work:
<?php the_category('title=category_description()'); ?>
but it is not. I know that is a pretty hilarious way of solving this to most of you but I am completely lost. I just want the description of the category to be the title attribute. Is there a simple way that I can do this?
wordpress codex
using get_the_category(); you can save all of the categories into a variable.
Ex:
$categories = get_the_categories();
There is however an optional parameter that you can pass; the category ID.
Ex:
$categories = get_the_categories(THE_CATEGORY_ID);
Whether you present a category ID or not you must run $categories through a loop.
Ex:
foreach($categories as $category){
}
Only then, will you be able to customize your title attribute without modifying the wordpress code.
Ex:
foreach($categories as $category){
echo ''.$category->cat_name.'';
}

Magento :: Categories and Subcategories

Please anyone can help me how to design category and subcategory listing as below
http://www.officemax.com.au/office-supplies/writing.html
PS:: Magento default design is when you click a category it will list all products in that category straight. What I really want to do is , it should list all the subcategories first in the page like the above sample site http://www.officemax.com.au/office-supplies/writing.html and then list all relevent products of that subcategories
I will greatly appreciate if some one can help me.
Sub Categories within Categories - This is sample, you should customize
1.- Create a page called subcategory.phtml in the app/design/frontend/base/default/template/catalog/navigation folder and add following code piece :
<?php $_categories = $this->getCurrentChildCategories(); ?>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<?php echo $this->htmlEscape($_category->getName()) ?>
<?php endif; ?>
<?php endforeach; ?>
2.- Create a static block called "MySubcategory" and put the following code into content :
{{block type="catalog/navigation" template="catalog/navigation/subcategory.phtml"}}
3.- Now go to category which you would like to use to show sub categories and ensure that category not set as an "anchor". In the display option tab, set it to show as "Static Block Only" and choose the block "MySubcategory"
Use Easy Catalog Images module:
http://www.magentocommerce.com/module/1562/magento-easy-catalog-images

Get Wordpress Category from Single Post

I'm finishing up a WP theme, and I'm on the single.php template. I'm having some issues because I need to access the parent category that a post is in in order to display certain images and XML content.
Here is an example of what I'm talking about. The following is the end url of a single post:
/andrew/leaf-art-2/
/andrew/ is the category, and leaf-art-2 is the single post. When I am on the single post, I am having trouble getting single_cat_title(); to return the category that the current post is in. I am using single_cat_title(); instead of the_category(); because it displays the string value of the category which I then use to place a picture of the artist (whose category this is) on their posts. I don't have any use for the url, I just need the string with the category name.
Any good ways of doing this? I have been searching the Wordpress Codex and lots of forums, and haven't found any answers yet.
The following was my original post.
I have set up a category called "artists" which when I run single_cat_title("", false); I can get the string value of the category and then use it to search for the appropriate artist image using XML.
This works fine on the category.php template page.
The problem is that when I'm actually inside of a single post that has the "artists" category, single_cat_title(); doesn't output any information to the page, thereby keeping me from accessing the XML data.
I need to, while in the "artists" > "sample" post, be able to get from WP the category.
P.S. the above category is one of many that is using this setup, which is why I can't hardcode it.
How about get_the_category?
You can then do
$category = get_the_category();
$firstCategory = $category[0]->cat_name;
For the lazy and the learning, to put it into your theme, Rfvgyhn's full code
<?php $category = get_the_category();
$firstCategory = $category[0]->cat_name; echo $firstCategory;?>
<div class="post_category">
<?php $category = get_the_category();
$allcategory = get_the_category();
foreach ($allcategory as $category) {
?>
<a class="btn"><?php echo $category->cat_name;; ?></a>
<?php
}
?>
</div>
Get category names with permalink in single post without loop
the_category(',', '', get_the_ID())
If you want only the first one:
get_the_category(get_the_ID())[0]

Any idea why Wordpress's inCategorgy tag is not working?

So I am trying to add a "-none" to a class for a post if it is in a specific category in Wordpress. So like lets say if I am viewing a post that has a category id of 7, i want a certain class titled "example" change to "example-none".
Here's my code:
<div class="example<?= is_category('events') ?'-none':'' ?><?= in_category('7') ?'-none':'' ?>">
The weird thing with the code is, it works in a page when I am viewing all the posts in a specific category. But when I go to an interior post that is in a specific category, the code does not work.
I am using the in_category('7') tag to achieve this on a wordpress sidebar.
Any idea on what I am doing wrong?
I would remove the quotes around the id of the category:
in_category(7)
This should be a number, not a string.
Thanks. i got it working using this code:
<div class="example<? wp_reset_query(); ?><?= in_category(7) ?'-none':'' ?>">

Categories