Tag Info

New answers tagged

1

Just remove the trailing comma with some good ole php before echoing it out. $thelist = rtrim($thelist, ',');


0

There's a sql script written by someone else that does the job - updates counts for product categories in woocommerce or any other category counts. Only takes a few seconds to run as well: http://stackoverflow.com/questions/18669256/how-to-update-wordpress-taxonomiescategories-tags-count-field-after-bulk-impo


0

If I'm not totally missing some thing this should be achievable with a minor change to your code. You can not use post_class() in your code as it outputs/echos the classes. But there is get_post_class(), which does return the classes, but they are returned as a array. So you need to make a string out of it, to make use in your code. Lets do this just the way ...


0

Alright I figured it out! $args = array( 'post_type' => 'vendors', 'order' => 'asc', 'orderby' => 'title', ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { echo '<ul>'; while ( $query->have_posts() ) { $query->the_post(); $category = get_the_category(); echo '<li class="'; echo ...


0

Looks like all I needed was to include 'posts_per_page' => -1 in the $query_args array. Final, working code: <ul class="tag-list"> <?php $query_args = array( // Easier to call the parent category, "recipe" instead of dealing with all these ids // 'cat' => '101,94,93,56,72,99,100,63,98,95,96,80,4', ...


0

You'd probably be better served by creating a custom taxonomy to accompany your custom post type. That way you can manage terms separate from the built-in categories taxonomy. // Register Custom Taxonomy function wpse_168762_create_gallery_taxonomy() { $labels = array( 'name' => _x( 'Gallery Categories', 'Taxonomy ...


-1

Use filter single_template to change template file and function in_category to check is this post in category. add_filter( 'single_template', 'my_single_template' ); function my_single_template($single_template) { if (in_category(1)) { $file = get_template_directory().'/single-cat-1.php'; if ( file_exists($file) ) { return ...


0

You can use this function to add category specific single template pages on your website. This goes in functions.php You can define as many single templates as you want. function wpse_category_single_template( $single_template ) { global $post; $all_cats = get_the_category(); if ( $all_cats[0]->cat_ID == '1' ) { if ( ...


0

Here's my take on it: $categories = get_categories( $args ); foreach ( $categories as $category ) { $image = (function_exists('z_taxonomy_image_url') && z_taxonomy_image_url($category->term_id) ) ? sprintf('<img src="%s">', z_taxonomy_image_url($category->term_id) ) : ''; echo sprintf('<li>%s<a href="%s" ...


2

According to the plugins documentation (http://zahlan.net/blog/2012/06/categories-images/), this seems pretty simple: <ul> <?php $categories = get_categories( $args ); foreach ( $categories as $category ) { $img_src = z_taxonomy_image_url($category->term_id); if ( $img_src ) { echo '<li><img src="' . $img_src . '" ...


0

You could try this. $categories = get_categories( $args ); foreach ( $categories as $category ) { if (function_exists('z_taxonomy_image_url')) { $imgurl = z_taxonomy_image_url(); } if ( $imgurl ) { echo '<li><img src="'. $imgurl . '"/><a href="' . get_category_link( $category->term_id ) . '" ...


0

You can simply loop over the categories that you don't need. get_the_category() return an array of categories that the post belongs to. With that in mind, you can do the following: (Just remember to change 21 and 41 to your desired ID's) $categories = get_the_category(); foreach ( $categories as $category ) { if( 21 === $category->cat_ID || 41 === ...


1

There is nothing directly meant for that (that I can think of), but there is very close in purpose function get_default_post_to_edit(). Since for the purpose of new post creation it makes post appear in DB before it is even saved for the first time (as auto draft) we can tinker with its filters a bit to make it happen: add_filter( 'default_content', ...


0

As said in one of the comments, this is really simple. Within your theme folder, you can create a file called category.php. Once in place, you can modify to your hearts content without the need to do anything fancy such as redirection. If you want to target a specific category, let's say music, then the file would be category-music.php It's also worth ...


0

First, search for the function tie_last_posts_cat**. It's probably inside functions/theme-functions.php Then search for $lastPosts = get_posts('category='.$cats.'&numberposts='.$numberOfPosts); Change it to $lastPosts = get_posts('category='.$cats.'&numberposts='.$numberOfPosts.'&orderby=rand'); Hope this helps This might also help


0

Have a try, I din't test. On line 48 change: $categories_obj = get_categories(); with $categories_obj = get_tags(); And also look for the tie_last_posts_cat() function in your code, and modify it accordingly.


0

Just a note to potential downvoters and close voters, even though this question by itself is on topic, the reason that this being a core theme, make this even more on topic EDIT As you are making use of the twentyfourteen theme, you have to remember this one golden rule ( and this applies to all themes and plugins that you are not the author of ), you ...


2

SIDENOTE: This function can be used even if have posts belongs to one taxonomy only. You don't need to have a post that belongs to two or more taxonomies within the same hierarchy. I have made this function very flexible It is always a problem for me to display a category list or term list for a post if the following conditions occur Having a post having ...


0

This might help you to get categories of particular post $catList =get_the_category($post->ID); foreach($catList as $single){ echo $single->cat_name; } You can also check from below links get_the_category get-category-name-from-post-id


0

The functions you have tried are for terms by themselves, just existing in site. What you are looking for is get_the_terms(), which retrieves terms of specific taxonomy, assigned to specific post.


0

For hierarchy purposes, another USEFUL way: use Custom_post_types instead of Categories, like here: How to change permalink structure for custom post type and it's taxonomies?


0

Please, read 2 ADVICES: for example, you want to have(like category) such permalink structure: /new_cars/ferarri/2-doors /new_cars/mercedes/2-doors /new_cars/mercedes/2-doors/my-post1 (unique or duplicate slug names doesnt matter in this case) ...... At first, you may need to set permalinks to /%category%/%postname%. then... METHOD 1: you can register a ...


0

I'm not sure why you're getting the '0's. But you shouldn't be using 2 switch statements in work_custom_columns(). Try this: function work_custom_columns($column){ global $post; switch ($column){ case "work_category": echo get_the_term_list($post->ID, 'work_category', '', ', ',''); break; ...


1

$category = get_category($latest_issue); // it is category object echo $category->title; echo $category->description; in codex: http://codex.wordpress.org/Function_Reference/get_category But i think you should get category not by last created ID, but by slug: http://codex.wordpress.org/Function_Reference/get_category_by_slug So you should change: ...


1

Simplest way to do this is by way of this excellent plugin: https://wordpress.org/plugins/term-management-tools/ Once installed it will allow you to consolidate categories just as you wish.


1

Please try the following code: Following code has to be added in shortcode function global $wpdb; $start .= $attr['godina'] . "-09-01"; $end .= $attr['godina'] + 1 . "-08-31"; $cat = $attr['cat']; //$cat must be category name. $cat_term_id=get_term_by('name', $cat, 'category'); $term_id=$cat_term_id->term_id; $query = array( ...


2

Thanks guys, I found a solution: It's as easy as adding the post_type_category element to the arguments object within register_post_type(): $args = array( 'label' => 'sausages', 'description' => 'Sausages', 'labels' => $labels, 'post_type_category' => 'food', 'supports' => ...


1

I am make some assumptions here on where you are needing this but you could use is_post_type_archive() to check for archive pages and is_singular() for individual single posts both take either an string or array of post types. $post_types_group_one = array('movies', 'apples', 'sausages' ); $post_types_group_two = array('movies', 'apples', 'sausages', ...


1

I'm assuming you're not using a plugin to register your post types and doing them yourself. WordPress doesn't have an easy way to group or categorize post types together like what you're asking for. What I would suggest is to use built in attributes in a custom way. For example, when registering your post type there is a field called description. I don't see ...


-1

You check if Product is associated with any Collection or not. $term_list = wp_get_post_terms($post->ID, 'collections', array("fields" => "all")); Returns an array of All term Items for taxonomy "collections". IF $term_list has values you can display collection(s) using a loop $name = $term_list->name; $link = $term_list->link;


1

EDIT From your comments, you are using get_cat_ID() totally wrong. You can only feed one category to it. Please follow all links given and check the examples in the codex. Also, as stated, enable debugging, because that is all problems you should have picked up Secondly, it seems that you are using a custom taxonomy and not the build in category structure, ...


0

thanks @BA_Webimax i've found the solution by using this query inside my subdomains pages to get datas from my main domain pages. main domain blog ID is (1). and sub domain for example are 2 and 3. <?php switch_to_blog(1); ?> <?php restore_current_blog(); ?> look like this to display on a page from a sub domain, all the titles from posts ...


0

What you can do is to set up a pre_get_posts() filter in the subdomains' theme functions.php file to restrict posts to the desired category... function my_subdomain_category( $query ) { if ( $query->is_main_query() ) { $query->set( 'cat', '123' ); // use the categoryID for space or products } } add_action( 'pre_get_posts', ...


0

Before questioning please search for the available resources. I've found two available plugins: Categories Images - WP Plugins WPCustom Category Image - WP Plugins I personally used the first one, and grabbed the necessary code from the plugin to implement my own version, and it worked perfectly.


1

To show all categories on a page, you will have to create a new page template. <?php /** * Template Name: Categories Page **/ get_header(); ?> <!-- content --> <div id="content"> <ul class="category-list"> <?php wp_list_categories( 'title_li=' ); ?> </ul> </div> ...


0

'category_name' will not work. You are making use of a custom taxonomy, not build-in categories. It seems from this that you have a misunderstanding about taxonomies. Please take your time and see this post on this particular subject For custom taxonomies, use a tax_query to retrieve the posts that you need. Here is an example: $query_images_args = array( ...


0

I have written a quite extensive post on a similar subject that you can read here. Also take your time and read all linked posts. In there I have explained why you should not be using query_posts and why you should not use custom queries in place of the main query A few things here: Remember to create a child theme, do not make changes to a theme that ...


2

Your $args array is incorrect. You used cat=-8 which is not correct here. You will have to specify/exclude category this way 'cat' => -8. So your $args array will be $args = array( 'posts_per_page' => 3, 'orderby' => DESC, 'cat' => -8 );


0

One quick way of doing it without having to set up multiple loops would be to use the get_posts() function and grab all pages, then check through them with in_category() and split out pages that are in the category and pages that are not. You can then run through the 2 groups of pages separately in your ULs with a simple foreach loop. <?php $args = ...


0

It seems that you need to do this inside a post. For this, you can either use has_category() or in_category to test if a post belongs to the given category, and if the condition is true, apply your changes Example: if( has_category('name or I'd or slug of category to test) ) { echo '<img src="http://organeek.net/wp-content/uploads/2014/10/85.jpg' . ...


2

category__in will never work as you aren't making use of the build in taxonomy category. You are actually making use of a custom taxonomy called tagbbt. Take a look at this post, I have explained what the differences are For custom taxonomies, you need to make use of a tax_query Here is an example $args = array( 'post_type' => 'bbt', ...


2

Take a look the section called Preserving Existing Query Parameters on http://codex.wordpress.org/Function_Reference/query_posts Try merging in the existing query parameters; they might be getting overridden. Instead of: <?php query_posts('cat=4'); ?> try global $query_string; query_posts( $query_string . '&cat=4' );


1

This is how its done in Twenty Fourteen which uses a template tag: Note: The conditionals if ( is_sticky() && is_home() && ! is_paged() ) { will need to be changed or removed if ( ! function_exists( 'twentyfourteen_posted_on' ) ) : /** * Print HTML with meta information for the current post-date/time and author. * * @since Twenty ...


0

So @Sharma, The file you are looking for is the archive.php, but if you cannot change the things you want is because the archive.php is including another file for that. A good way to check Template files and how the behave, is the Codex Page about Template Hierarchy. If you don't find what you are looking for on your archive.php please post it's ...



Top 50 recent answers are included