Wordpress Categories Linking to Subcategories - wordpress

I'm trying to accomplish a three-step page hierarchy in Wordpress.
Here's an example of what a breadcrumb navigation might look like:
Mathematics > Algebra > Variables
I've got a page that lists all of my top-level categories:
<?php wp_list_categories('depth=1'); ?>
What I need next is to make it so when you click a category, it links you to a page that just lists all of its subcategories. By default it takes you to a page with every post in that category.
So you could select say Math on the first page, followed by a page with sub-categories like Arithmetic, Algebra, Geometry, and then when you select your sub-cat it takes you to the posts.
I'm open to using any alternative methods too if you've any ideas on a better way to do it. Using the built-in category system just seemed most appropriate.

wp_list_categories can take an argument, 'child_of', that will return a list of child categories. So, in your individual category listing page, you can use the category id of the relevant category to retrieve the children like this:
<?php $children = wp_list_categories('child_of='.$your_category->cat_ID); ?>
Further documentation for wp_list_categories can be found here: http://codex.wordpress.org/Template_Tags/wp_list_categories

Related

Post-meta data author and date for specific category

I want display post-meta like author and date for specific categories only, like i have 3 types of categories blogs,news, comments , now remove post-meta like author and post date from blogs and news category posts.
you have to use wordpress neat function is_category() and where the parameters you need to give are your blogs,news, comments
Now for eg if you want to display in single page where posts from these categories only need to show up then you must have these three categories id and you can apply conditions like
if(is_category('1','2','3')){
//your codes here
}
Take reference from this
https://developer.wordpress.org/reference/functions/is_category/
Create a new custom category template.
1. Inside you theme folder duplicate the category.php file.
2. Rename the duplicated copy to something like category-news or category-23(whatever you prefer which must match with the category slug or ID respectively).
3. then change the content of that file.
Whenever you navigate to that category(slug=news or id=23), wordpress automatically looks for category template(slug or Id) that matches the target category page something like (category-news.php or category-23.php files) if the file isn't found it moves to category.php.

Adding additional names to a category in Wordpress

Strange question which is typically against how Wordpress works but I'm wanting to add additional names to a category, almost like a "also known as".
So might have "Tech talk" as what the category is called but wanting to add "Bob Billy" (for example) as what the category can also be known as. I know about sub categories and this isn't what I mean.
Thanks.
In wordpress categories, have description. you can use the description and show it anywhere on your blog/website. this is the case where you have just one alternative for each category and not more.
According to the documentation:
<?php echo category_description( $category_id ); ?>
Returns the description of a category defined in the category settings screen for the current category (Posts > Categories).
Please let me know if it fits your needs, or I will hand you another way to acomplish that :)

Wordpress yearly archives for current category

This has really been driving me mad for a while now, so I'm hoping someone can help. I'm trying to use wp_get_archives() to display a list of links to yearly archives that show posts within the current category.
Importantly, I'm trying to do this without a plugin and just use the functions file or even a WP_Query loop.
Example
Imagine I have the following categories all filled with posts:
Exhibitions (parent)
--Current (child)
--Past (child)
Artworks (parent)
--Recent (child)
--Featured (child)
--Old (child)
What I'm trying to do is essentially this:
/* Get current Cat ID */
function getCurrentCatID() {
global $wp_query;
if(is_category() || is_single()){
$cat_ID = get_query_var('cat');
}
return $cat_ID;
}
$currentCat = getCurrentCatID();
wp_get_archives('type=yearly&cat=$currentCat'); // But, you can't filter this by category it seems
So, if I view the 'Exhibitions' category (which uses category.php), wp_get_archives() would show links for 2012, 2011, 2010 etc.
When I click 2011, I would see posts that are in the category 'Exhibitions' AND it's child categories (also important).
I've found this post which might hold the answer: Exclude Category From wp_get_archives?
But I don't know how I would use the current category being viewed within filters mentioned in the post nor how I would add multiple categories to it (i.e. the parent category plus it's children).
Any help massively appreciated.
Osu
The way I read this, there's two facets to this question. The first has to do with generating and printing links. But there's also the matter of those links leading to URLs that exist. This might help with that second bit:
http://wordpress.org/support/topic/per-category-date-archives-not-working
I used it sucessfully once to generate "/category/date/" style URLs.

How to use loop on static page in wordpress?

I want to loop posts form different category on static page. So , I have 5 static pages , and 5 different categories. I want to loop posts from one category per one page.
The way I do it is this:
> $novo = new WP_Query('cat=3'); // 3 is category id I want display
> while($novo->have_posts()) : $novo->the_post();
>
> <!-- post model -->
>
> endwhile;
The problem with this that I don't know how to display pagination in static pages with many posts in single category.
What's the best way to make loop on static pages with easy navigation implementation?
what you usually use to make loop on static page?
Any help is appreciated :D
First of all, the question is wrong. An static page is one that DOES NOT HAVE QUERIES or receive any kind of information from other sources.
If you want to paginate a single post wich has more than one page, you should use:
<?php wp_link_pages('before=<p>&after=</p>&next_or_number=number&pagelink=page %'); ?>
If you want to paginate a page wich have N posts:
wp_pagenavi():

Wordpress multiple / exclusive posting pages

I want a site with a separate News and Blog page, ie only news posts are dispayed on news pages and non news posts on blog pages. Also archive lists, category lists, etc for each page must only display relevant posts. Seems like a common requirement, but using the WP documentation, I keep going around in circles!!! Is there a simple way to do this, without getting into multiple blogs, eg using categories.
Thanks
That's easy.
First, you will need to create custom page template. Refer to this page to see how to create it.
Second, on that page (you can copy from your page.php/index.php, the important part is:
if (have_posts()) : while (have_posts()) : the_post();
Find that piece and add this code just right above that code:
query_posts('cat=3&paged='.get_query_var( 'paged' ));
Things to note from above query_posts snippet is:
cat: this is the category ID you want to query. To easily see what ID is on a particular category, you can use ShowID for Post/Page/Category/Tag/Comment plugin.
paged: Paged will allow your custom page to handle next & prev navigations, which is handled by next_post_link() and prev_post_link(). As for get_query_var( 'paged' ) is function to get what page's page you currently see.
Hope that helped.
<shamelessplug>
I blogged it here (in Bahasa Indonesia, which you can easily translate using google translate).
</shamelessplug>

Resources