Tag Info

New answers tagged

1

is_category() does this: (...) Checks if a Category archive page is being displayed. (...) One line below on the codex page you find: To test if a post is in a category use in_category(). So just use the latter.


1

Before I start again, I just want to reinforce the fact you should not run a custom query in place of the main query on your archive pages. Please see this post to learn when you should use a custom query and where not. I you do not switch back to the default loop, then my solution will not work In the previous post we have already solved the issue to only ...


1

The simplest would be to add a series of two very short (mu-)plugins. This also adds routes for page/2, etc.: http://example.com/u/%author% <?php /** Plugin Name: (WPSE) #46074 Add /u/%author% routes */ register_activation_hook( __FILE__, function() { flush_rewrite_rules(); } ); register_deactivation_hook( __FILE__, function() { ...


1

Looking at the source code for wp_get_archives(), there is a filter called getarchives_join which you can use to restrict wp_get_archives() to a specific category You also need to get the current category ID, which is easy, simply use get_queried_object_id() You can try something like this to display archives for the currently viewed category add_filter( ...


0

To get the name of the child categories. I have used @Howdy_McGee's function for a quicker & iterative process. function category_has_children( $term_id = 0, $post_type = 'post', $taxonomy = 'category' ) { $children = get_categories( array( 'child_of' => $term_id, 'type' => $post_type, 'taxonomy' => $taxonomy, 'order' => 'ASC', ...


1

You could use this simple function call which returns either TRUE or FALSE depending on if $children is an empty array or not. function category_has_children( $term_id = 0, $post_type = 'post', $taxonomy = 'category' ) { $children = get_categories( array( 'child_of' => $term_id, 'type' => $post_type, 'taxonomy' => $taxonomy ) ); return ( ...


2

I think it will be easier to make use of the category slug, and not the name. It is already in lowercase and hyphen separated if you have more that one word. The problem with using the name and adding hyphens is that you will not get a match and most probably just 404. %20 is how blank spaces is encoded in a URL. You can just replace $category->cat_name ...


2

Try this <a href="/category/<?php foreach((get_the_category()) as $category) { echo $category->slug . ' '; } ?>"> Hope this helps.


0

What you need is switch_to_blog and maybe get_blog_id_from_url which you would use like this: $blog_id = get_blog_id_from_url( 'www.example.com' ); switch_to_blog( $blog_id ); wp_create_category( 'mycategory', 0 ); restore_current_blog();


0

Change this: echo $category->cat_name To this: echo $category->cat_slug A better way would probably be to use: $cat = get_the_category(); $cat_link = get_term_link( $cat ); That will have $cat_link as the full permalink. echo '<a href="' . $cat_link . '">' . $cat->cat_name . '</a>'; Using your code above: <a href="<?php ...


0

I would use WP_Query for this, as I am more comfortable with it. There are two solutions to this that occur to me. If you're not heartset on the categories, then WP_Query has good support for date parameters, to include a year parameter. A query by year would look something like this: $wpse176213_query = new WP_Query( array( 'nopaging' => true, ...


0

The next_post_link() and previous_post_link() functions have parameteres as follows - $format (string) - You've already included this. $link (string) - You've already included this. $in_same_term = false (boolean) - Whether or not all linked posts should be within the same taxonomy term. Chances are this should be false if you are looking to exclude a ...


1

You can make use of the the_content filters to apply markup to get_the_content() $content = get_the_content(); echo apply_filters( 'the_content', $content ); You'll need to do the same for get_the_title() where you would use the_title filters instead of the_content Just another note on your code, remember to reset each of your custom loops with ...


1

I believe, most obvious choice would be to create two categories "Fall-Winter" and "Spring-Summer" and put four other categories in both of them. Your URLs would be like this /category/fall-winter /category/fall-winter/formal-wear /category/fall-winter/night-wear Now, to list the formal wear for both fall-winter and spring-summer on page, we have few ...


0

If your theme has an attachment template (attachment.php) and you upload your page/post-specific media items, then you will get a page/post-specific media attachment URL. Suppose you are adding/editing your post/page on Case Study (i.e. cs1), so your post/page URL will be (if post-name permalink structure is enabled): http://example.com/cs1/ If you ...


0

WordPress has a pretty good inbuilt bulk editing system. Just select all the products/post for each category and select bulk edit from the menu where you'd normally see more to trash.


0

The best way to add extra fields to the wordpress user registration form that I know of is to use the related registration form filters: register_form - This is used to add your fields to the registration form registration_errors - This is used to validate your fields user_register - This is used to add your custom user_meta data to the system and maybe ...


0

WordPress determines which template file to use from its Template Hierarchy. It might be further customized by extensions and themes might be using different files for same things, depending on what they do. There are helper plugins for simpler cases (for example What The File), but it might require involved debug with more complex themes.


1

Yes, there is. Paste this in your function.php add_action('pre_get_posts','wpse_175699_alphabetical_order'); function wpse_175699_alphabetical_order($query) { if (is_category()) { $query->set('orderby', 'title'); $query->set('order', 'ASC'); } }


0

If you're talking about general Wordpress coding, have a look here: http://codex.wordpress.org/Alphabetizing_Posts Look for 'order' => 'ASC' which will order posts in Ascending value (eg. A-Z) If you're talking about using or adapting a plugin, have a look in the plugin's instructions. For instance, the plugin List Category Posts has instructions about ...


1

2 Years later, there is a WordPress plugin that does this. Checkout "Featured Images for Categories" https://wordpress.org/plugins/featured-images-for-categories/


0

You should create a taxonomy template, not a category. I suspect that you have misunderstanding about categories, terms and custom taxonomies. I would suggest that you read my post on this particular subject here Study the taxonomy template hierarchy in the linked page in your question As for the 404 page, you most probably haven't flushed your permalinks ...


0

ok folks, i did it anothere way.. here's how i did it: add_filter( 'pre_get_posts', function( $query ) { if( ! is_main_query() || ! is_post_type_archive() || ! $query->get( 'section', false ) ) return $query; global $wpdb; $section = $query->get( 'section' ); unset( $query->query['section'] ); unset( ...


0

function my_Categ_tree($catId, $depth){ $depth .= '-'; $output =''; $args = 'hierarchical=1&taxonomy=category&hide_empty=0&parent='; $categories = get_categories($args . $catId); if(count($categories)>0){ foreach ($categories as $category) { $selected = ($cat->term_id=="22") ? " selected": ""; ...


1

In both your queries you are doing it wrong. You are running a separate instance of WP_Query for every argument set $args = array( 'posts_per_page' => $count, // Limit count ); $query = new WP_Query( 'cat=1' ); $query = new WP_Query( $args ); Should be $args = array( 'posts_per_page' => $count, 'cat' => 1 ); $query = new WP_Query( $args );


1

Don't nullify the main query, this breaks stuff. Also, avoid using the $wp_query global as a custom variable. This breaks the main query and causes issues. You can also try adding 'suppress_filters' => true, to your arguments to suppress any custom filters if you are using any custom filters. Also, don't use TEMPLATEPATH, it is due to be depreciated ...


0

It seems like there was some kind of problem with my multisite setup which caused WordPress to fetch the categories from some other blogs posts. (Can't really tell where from actually). However by writing switch_to_blog(1) (which it always will be) it seemed to work as it should.


0

By default, you can view posts by authors with a URL of the form {home_url}/author/{author-slug}/ If you'll be writing any PHP and need to output a link to an author's posts, see the function get_author_posts_url. Edit: If you'll be writing your own author post page template, the filename should be one of the following formats: author-{nicename}.php, ...


0

You can use <?php $categories = get_categories( $args ); ?> <?php $args = array( 'type' => 'post', 'child_of' => 0, 'parent' => '', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, ...


0

Use category__in instead of cat in your query. As you know already, cat will query a category and it's sub categories: $category = get_category (get_query_var('cat')); WP_Query( 'cat'=>$category, 'post_type' => 'post' ); However, when using category__in, you'll will not get results from the subcategory. $category = get_category ...


0

First, you should change your input field names to something unique. category is a WordPress query var, so submitting a form with that field name may have unexpected results. That said, post_category is only for the category taxonomy, custom taxonomies should use the tax_input parameter. however... if this form is being submitted by users who are not ...


0

I found what I needed: $category = get_category( get_query_var( 'cat' ) ); $cat_id = $category->cat_ID; $images = get_posts( array('post_type' => 'attachment', 'category__in' => $cat_id)); if ( !empty($images) ) { foreach ( $images as $image ) { $image_url = $image->guid; } } else{ $image_url = ''; } First I got the ...


1

Try adding this in your functions.php file: // Let's stop WordPress re-ordering my categories/taxonomies when I select them function stop_reordering_my_categories($args) { $args['checked_ontop'] = false; return $args; } // Let's initiate it by hooking into the Terms Checklist arguments with our function above ...


0

I got it to work by doing it this way if (is_admin() ){ $post_id = isset($_GET['post']) ? $_GET['post'] : isset($_POST['post_ID']) ; if( $post_id && in_category('audio', $post_id) ){ add_action('admin_init', 'add_meta_boxes', 1); } } The only problem with this method is that it won't display the metabox until after you have published the ...


0

I'd recommend using an action to place your meta box: function my_add_meta_box() { global $post; if ( $post && is_a( $post, 'WP_Post' ) ) { $cat = get_category_by_slug('audio'); if ( !is_wp_error($cat) ) { if ( $post->ID == $cat->term_id ) { add_meta_box( 'repeatable-fields', 'Audio Playlist', ...


0

Hmm, I see you're using the get_categories() function to retrieve all categories. That function is returning an array with category objects. This means you have to edit the foreach loop, because $category is an object. $form_fields["custom4"]["html"] .= '<option value="' . $category->term_id . '">' . $category->name . '</option>'; Have ...


0

The way you're appending a foreach loop to a variable is not possible. Try this: $form_fields["custom4"]["html"] = "<select name='attachments[{$post->ID}][custom4]' id='attachments[{$post->ID}][custom4]'>"; foreach ($categories as $category) { $form_fields["custom4"]["html"] .= '<option value="$category">' . $category . ...


0

Did you try: function exclude_category($query) { if ( is_page('slug-of-page') && isset($query) ) { $query->set('cat', '-3'); } return $query; } add_filter('pre_get_posts', 'exclude_category');


1

You can use categories with pages by registering the category taxonomy for the page object type: function categories_for_pages(){ register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'categories_for_pages' ); If you want to use a separate taxonomy for this, you can register your own taxonomy for pages.


0

I bet you have a page named "Blog" with a slug "blog" in your system too? You can't have that with the permalink structure you have created because the permalink for this page would also be /blog/ and therefore cause a conflict. Try changing the slug of the page "blog" to something else.


0

You firstly need to login to your WordPress dashboard, and find the Categories button in the Posts tab. Then, you can add new categories as you wish. Next, back to the Appearance tab and click the Menu button. Then, create a new menu with the name you like. Now, you can add your newly created categories into the Menu. After saving changes, you are done. ...


-2

You can create a page template (for service page) and then set it to particular page, on which you want to display posts. After that open page template and paste below code where you wan to show posts. <?php query_posts('cat=1'); // cat=1 , id of category you want to show (e.g. cat id of food category ) while (have_posts()) : the_post(); // loop for ...


0

I found this handy solution which you can use without plugin. http://stackoverflow.com/a/27569173/851045 function fix_slash( $string, $type ) { global $wp_rewrite; if ( $wp_rewrite->use_trailing_slashes == false ) { if ( $type != 'single' && $type != 'category' ) return trailingslashit( $string ); if ( $type == 'single' ...


0

I presume there is an open option html element before that code provided. After that select tag is opened and before you run through that loop echo out a blank option with value=""


0

Admittedly a clever solution, and one that works fine within the scope of your original question. For future readers with similar use cases' reference though I would suggest they also consider creating a multisite (network) install. When used purely for sub domain sites (ie no domain mapping) it's not greatly more difficult to create and manage than a ...


0

The answer is essentially the same as my Edit 2 code. I must have had a typo the first time? I've tried to comment on what each thing does... The code works but the comments could be way off. I'm new at this. Also, this same code should work your author archive. As one helpful person pointed out, this code is really useless and is not at all what Wordpress ...


0

Your issue here likely is the action 'publish_product' not firing - it only runs when you first create a product, or set a products status from Draft or Pending Review to Publish. Be aware that wp_set_object_terms will overwrite any other existing category data with the last parameter set to false, in your code those products would end up with only the one ...


0

wp-config.php if ( is_alt_domain( $_SERVER['SERVER_NAME'] ) ) { $domain = str_replace( 'www.', '', $_SERVER['SERVER_NAME'] ); define( 'WP_SITEURL', 'http://www.' . $domain ); define( 'WP_HOME', 'http://www.' . $domain ); } else if (is_sub_domain( $_SERVER['HTTP_HOST'] ) ) { $domain = "{$_SERVER['HTTP_HOST']}"; define( 'WP_SITEURL', ...


0

Yes, Finally i had done it. I done changes in nav-menu-template.php. I created one variable and initialized with 1 above foreach ( (array) $menu_items as $key => $parent_item ) { this code. and add conditional code if($repetation == '1'){//to stop second selection of menu $classes[] = 'current-menu-parent'; ...


0

The best way to achieve content separation between sites is to separate their DBs. As a rule of thumb it is easier to aggregate content the separate it, search, RSS feeds, social sharing, SEO might need to behave differently on different subdomain, and there is no way the kids will agree to the design imposed by the "old guys". The easiest solution is to ...



Top 50 recent answers are included