Tag Info

New answers tagged

2

Just use the break statement to abort after the first cat that is found and that is a child category. foreach ( get_the_category() as $cat ) { if ( cat_is_ancestor_of( 10, $cat ) ) { printf( '<a href="%s">%s</a>', get_category_link( $cat->cat_ID), echo $cat->cat_name ); ...


0

your code may look like <?php $category = get_the_category(); if($category[0]->parent == ' your_parent_category_id ( Premium )'){ echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>'; } ?>


2

get_query_var will get the category from the main query, and it is only going to be set for some pages, such as category archives. It is not set for "single" pages or tag archives or a many other kids of "pages". The value that get_query_var returns is something like a 'search' variable. It will be set when the query is instructed to look for posts in a ...


0

You might try the the_content filter with the conditional tag is_category() to append a string to the post content when viewing the category archives : add_filter( 'the_content', 'custom_the_content' ); function custom_the_content( $content ){ if( is_category() ): $metastime = get_post_meta( get_the_ID(), 'user_submit_starttime', true ); ...


0

What about checking the ID value of each menu item like the following: if( $item->ID === 45): // ADD THIS MENU-ITEM ID CHECK // Query the lasts ten category posts $category_ten_last_posts = array( 'posts_per_page' => 11, 'category_name' => 'mamba', 'orderby' => 'date', ...


0

You can rewrite you .htaccess if you are familiar with this. Add the below line and try it: RewriteRule ^category/(.+)$ http://www.site.com/$1 [R=301,L]


0

If you go to Settings->Permalinks you should be able to set the tag/category base URL rules which should solve this problem. Or, use some sort of plugin to do what you want. This one came up first on Google: http://wordpress.org/plugins/custom-permalinks/


1

You can use get_query_var( ) to fetch the current category: $cat = get_query_var( 'cat' ); You can use this $cat in the exclude parameter of wp_dropdown_categories( ) to hide the current category: $args = array( 'show_option_none' => __( 'Select A Category' ), 'show_count' => 1, 'exclude' => $cat ); wp_dropdown_categories( $args );


0

Try using the exclude parameter. wp_dropdown_categories('show_option_none=Select A Category&show_count=1&exclude=45'); Where 45 is your current category ID.


0

The parent category (hardware) you should display this category in any page by getting all the parent categoty using $parent_category = get_categories(array('orderby' => 'name','parent' => 0)); foreach($categories as $category) { echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View ...


0

Hope this will match your question : create a search page. To customize search results you have to add a file called search.php to your theme.


0

If you want to apply the same logic to the category archives and the search results as in that question you reference, the following should do it. // modified code from http://wordpress.stackexchange.com/a/97589/21376 function hide_on_home_page_wpse_97587($atts,$content) { if (!is_home() && !is_category() && !is_search() ) { ...


1

The default exporter will do this. Instead of selecting "All Content", choose "Post" and then a category.


0

Retrieving set of posts by some criteria is typically realm of secondary loop. You can use get_posts() template tag or WP_Query object which both support author parameters in arguments: author (numerical ID) author_name.


1

There is no category argument for query_posts, a category ID should be passed via cat. However, if this is an additional query, please use WP_Query rather than query_posts. If this is the main query, please see pre_get_posts to alter the main query parameters. For more info please see When to use WP_query(), query_posts() and pre_get_posts.


0

I'm not really sure how to do this, but I found a plugin that seems to be able to do this. http://wordpress.org/plugins/tdo-tag-fixes/


1

You can't use the category name to search for categories. You can use the slug. Be aware of the difference. A slug is normalized to lower case with spaces replaced by dashes. The slug for "Foo A" would be "foo-a". Using "Foo A" will not work. $admin_cat = get_option('admin_cat'); if (ctype_digit("$admin_cat")) { // this is an ID $qry = array('cat' => ...


0

I would like to display a custom field in my Category Archives. So, you have to put the code into archive.php. I want the code to register on every post just like it registers in the single.php If I'm not wrong, you need the custom field to be shown in every pages where the post is echoed. If so, you have to follow the following steps specific to ...


1

If your Loop is constructed correctly $post will be set for each post in the loop in turn. You could also consider using get_the_ID. get_post_meta($post->ID, "user_submit_url", true); by itself won't do much. You will have to format and echo the information but that should retrieve your post meta data. For example, to generate a link (assuming your meta ...


1

Did you try BulkPress Plugin? Easily add and manage multiple categories, pages, custom taxonomy terms and custom post type posts. Create and reorder terms


3

It sounds to me like genre should be its own taxonomy. Then posts get assigned to both categories and genres. If you do it this way, here's what you need to do to get everything working: First, register the taxonomy genre. Next, assuming you're using the core posts and categories, go to Settings → Permalinks. Set your permalinks to be ...


0

You've created a structure that is going to be difficult to manage. Independent WordPress sites do not communicate by default, or readily, or easily. My suggestion would be to roll both sites into one with the course catalog being a custom post type with rigid controls over who can view the content. If that is not possible, then I'd suggest creating a kind ...


1

one solution to your problem using jQuery( put this code in functions.php ) <?php add_action('wp_footer','ravs_browse_menu'); function ravs_browse_menu(){ if(isset($_GET['cat']) && $_GET['cat'] !=''){ ?> <script> jQuery(document).ready(function(){ jQuery('#menu-item-299').addClass('current-menu-item'); }); </script> ...


2

I would suggest using Scribu's Posts 2 Posts plugin. It allows you to map posts to other posts as if they were a taxonomy like categories. The reason you would do it this way is that your categories for TV series etc... wouldn't have the kind of rich data you want attached to them and it'd be difficult to assign them to multiple genres otherwise. Plus as ...


0

I found this link to be helpful with the full function call and hooks to target, it even mentions the distinction between if the custom post type was created by a plugin: http://pippinsplugins.com/add-already-registered-taxonomy/


0

This is the loop I've created to display post's matching criteria on empty page: // get results $the_query = new WP_Query( 'meta_key=apaitei_logariasmo_facebook&meta_value=Ναι' ); // The Loop if( $the_query->have_posts() ) while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<h3>'; the_title(); echo ...


1

Try this function set_post_type_for_category_archive_wpse_101930($qry) { if ($qry->is_main_query() && $qry->is_category()) { $qry->set('post_type', 'news'); } } add_action('pre_get_posts','set_post_type_for_category_archive_wpse_101930'); Read how to customize wordpress query


0

I used the jQuery below to achieve this as well. $('label[for="description"]').parent().parent().remove();


0

What you seem to be asking is relatively easy with a filter on pre_get_posts. function set_post_type_for_category_archive_wpse_101930($qry) { if ($qry->is_main_query() && $qry->is_category()) { $qry->set('post_type', 'news'); } } add_action('pre_get_posts','set_post_type_for_category_archive_wpse_101930'); That will hijack your ...


1

See Taxonomy Parameters documentation - there is include_children parameter, which you can set to false in your taxonomy query.


0

try this while($qry->have_posts()){ $qry->the_post; foreach((get_the_category()) as $category) { //check if category have parent or not if ($category->category_parent == 0) { //your code goes here for post } } important Link: get_the_category()


0

I know this post was answered a long time ago, i used the solution from the answer, it works great but it displays an empty list with 2012 as headline, then it starts with 2007 with posts and then again 2012 but with posts. What's wrong?


1

This is fairly straightforward with a custom post type and custom taxonomy. First, register a custom taxonomy worktype, with rewrite parameter set to works: 'rewrite' => array( 'slug' => 'works' ) Next, register a custom post type with rewrite set to works/%worktype%: 'rewrite' => array( 'slug' => 'works/%worktype%' ) You'll also need to ...


0

First, don't use query_posts. There are no pagination functions that I can spot in your code. That is a big problem if you want pagination to work. Nor do you have a pagination parameter in your query_posts (which you should not be using) arguments. The simple pagination functions like next_posts_link may not work in your case anyway, without complicated ...


0

Change your permalink and set to this %postname%/ Its change your url Like a site url/category name/postname


1

Don't use query_posts(). Use pre_get_posts instead: function wpse82745_filter_pre_get_posts( $query ) { // Only modify the main loop, // and only in the blog posts index if ( is_home() && $query->is_main_query() ) { $query->set( 'category__not_in', array( '13' ) ); } } add_action( 'pre_get_post', ...


0

I was running into the exact same mysterious issue, but struggling to solve it. I tried all of the suggestions in the comments here but nothing seemed to work. In the end, since the key was retaining the pagination (as this was on the main blog section of the site and I wanted to exclude 'Other News'), I tried this: // Exclude the Other News category ...


1

How are you outputting the category description? You might need to use something like apply_filters('the_content', category_description( $category_id )); or wpautop(category_description( $category_id )); to have paragraphs in the output. Edit: Adding what you had in JSFiddle - note where $term->description is, I wrap it in wpautop. See if that works. If ...


2

Fairly simple using jQuery and global $typenow ex: add_action('admin_print_scripts-post.php', 'my_publish_admin_hook'); add_action('admin_print_scripts-post-new.php', 'my_publish_admin_hook'); function my_publish_admin_hook(){ global $typenow; if (in_array($typenow, array('post','page','mm_photo '))){ ?> <script ...


-1

<ul class="catTags"> <?php $args = array( 'show_option_all' => '', 'orderby' => 'count', 'order' => 'DESC', 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' ...


0

Is there any WP built in function which does the right job? No. [Do I] have to write a custom query for that? No. Use get_terms(). Here is an example. Add the wpse_99513_adjacent_category class to the functions.php theme file and call it like this: $category_ids = new wpse_99513_adjacent_category( 'category', 'id', false ); -- 'category' is ...


1

I found Ian Stewart's Theme Development tutorial a wonderful one to start from the scratch with a very little knowledge on WordPress. How To Create a WordPress Theme: The Ultimate WordPress Theme Tutorial Hope the explanation there could help you a lot to understand which code block's for what. So you can modify yours as you want. :)


0

You Can use the Parent / Child theme structure in wordpress to develop your own theme and style it as per your need. Minimal CSS Theme e.g. http://rtcamp.com/rtpanel/


0

Well, you need index.php, category.php, single.php, header.php and footer.php. The code should be something like this: index.php <?PHP $category_ids = get_all_category_ids(); sort($category_ids); foreach($category_ids as $cat_id):?> <!-- Category Start --> <div class="category" id="cat-<?PHP echo $cat_id; ?>"> ...


0

Have you created categories for both languages ? eg. if you have blog category in english then you have to create same as for other language. same for posts. If yes, then please check if language code filters is applied to archive page or not. if not then you have to make filter for language code. Thanks, Aezaz


0

As you want to define separate sidebar for : 1.post 2.and page 3.in post for category Place below code in your sidebar.php <?php if( 'post' == get_post_type()){ $categories = get_the_category(); foreach( $categories as $category ){ $sidebar_template[]='sidebar-'.$category->slug.'.php'; } //search for template for category ...


2

get_sidebar() accepts a parameter $name. Then will look for a file sidebar-{$name}.php. So what you can do is: get_sidebar( get_post_type() ); // search for sidebar-post.php or sidebar-page.php or: if ( in_category( array( 'featured-listing', 'listing-post' ) ) ) get_sidebar( 'listing' ); // sidebar-listing.php else get_sidebar();


1

I got the solution (based on the tutsplus tutorial link above) that deals with actual checkboxes here to work: http://wordpress.org/support/topic/display-tag-admin-box-like-categories-without-hierarchy it ignores the "most used" tab of the metabox that the tutsplus link addresses but personally I'm keeping it simple.


2

One way to do it is with the WordPress Template Hierarchy. If your category names/slugs are not likely to change you can have a separate template for each category. For example: category-books.php // will be loaded when viewing 'Books' category category-magazines-and-newspapers.php // will load for 'Magazines and Newspapers' category This way you can ...



Top 50 recent answers are included