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.
Related
When I use vc_map() to add a new element to the content element list there is the category parameter to put the element in a certain tab.
If there are to many category tabs, VC will put some of them in a dropdown list on the right hand side. Is there a way to rearrange the order of all tabs?
There's a filter that can be hooked into to rearrange the order of the element categories: vc_add_element_categories.
For example:
add_filter( 'vc_add_element_categories', 'rearrange_element_categories', 10, 1 );
function rearrange_element_categories( $tabs ) {
// rearrange the tabs according to your needs
return $rearranged_tabs;
}
Don't know why someone would need this? Still you can arrange this as per your choice by jumping into plugin's code.
Con:
It will get reset, when in future you will be updating the plugin. And as per our understanding for WPBakery Page Builder plugin, you can't survive by without updating it.
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 :)
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
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>
How am I able to show a single term of a custom taxonomy in Wordpress?
I have a custom taxonomy, which will always have only one term in it, and I want to display it in a custom loop on my home page. I have tried all possible ways, with one (blargh, can't remember which one) I managed to display the term but as a link, which I don't want. I need it as regular text, since I want to display it in my own href, which will link to the place where I want to.
Any ideas anyone? All and any help very much appreciated. This issue is slowing down my development of a custom theme. :(
Get the single term object using get_term($term_ID, $taxonomy), or alternatively get_term_by('slug', $term_slug, $taxonomy).
The term object will have, among other properties;
$term->name; // the name of the term!
$term->slug;
$term->term_id;
$term->count; // number of objects using the term