The tag has no wiki summary.

learn more… | top users | synonyms

4
votes
1answer
68 views

How to add classes to images based on their categories?

I need to be able to: 1.) assign categories to images and 2.) add classes to all images that correspond to their assigned categories. I was able to add categories to images with the following: ...
3
votes
1answer
257 views

Change role after the user has read all the posts in a category

I'm creating a platform with "X" categories and "X" roles with the same name to each category. I would like to know how to change the user's role after they have read all the posts in a category. ...
3
votes
2answers
4k views

How To Get Parent Category Slug of Current Post

My theme has styling by category using the following code, which inserts the current category's slug as a CSS class. <div class="CategorySpecificStyle <?php $category = get_the_category(); ...
2
votes
1answer
126 views

Get a variable from object in array [closed]

I'm trying to echo get_the_category($id)[0]->slug and this works on localhost but not on the server. The error is Parse error: syntax error, unexpected '['.... Is there a workaround?
2
votes
1answer
62 views

Get the category is not working on url

Although this is my first post but i have been coming here for answers so I know the rule and this isn't a duplicate because i have tried whatever i could but couldn't seem to get my codes to work. ...
2
votes
1answer
319 views

Display recent posts from the same category as current post in sidebar

I'm using a modified version of Twenty Twelve and I'm trying to display recent posts from the same category as the current post (except the current post) in the sidebar. I started this way but ...
2
votes
1answer
371 views

How can I get archives for specific category without category_base in the url?

I'm using this code to get archives for a specific category: function extend_date_archives_add_rewrite_rules($wp_rewrite){ $rules = array(); $structures = array( ...
1
vote
2answers
65 views

How to add a rel attribute to images that contains their categories?

I've added categories to images, so that I can use them to filter images within a portfolio page. Now I'm thinking I need to add the rel attribute to each image that contains its assigned categories. ...
1
vote
1answer
370 views

Add body class of category parent

I am not a coder, but I usually get by with Wordpress by doing my research and find my solution. I can't find what I need to do this time so I have attempted to crib together some code - what I am ...
1
vote
3answers
960 views

Add Class While on Current Post; wp_list_categories

The code below produces a sub-menu of child categories of the currently active parent category. This code also produces the child categories of the top parent category while viewing child categories ...
1
vote
1answer
168 views

Insert <ul> Into Sub-child Menu

This code displays a list of child categories of the parent category while a user is on a child category or single post. The styling around this list is displaying even when a list isn't being ...
1
vote
1answer
1k views

Add classname to the_category() function?

is it possible to use add_filter or something similar to add the slug of the category as classname to the the_category() function? Right now when using the_category() the output looks like this … ...
1
vote
2answers
137 views

Apply different Class for each element in a foreach()

sorry for the silly question, but I am really lost. I want to apply the following CSS to the even elements of my foreach. CSS .blogArticles a { float: left; max-width: 250px; width: 25%; ...
1
vote
1answer
88 views

Display post X of Y in category

I am trying to display a post number (X) on each single.php, based on what number that post is in it's category, followed by the total number of posts (Y) in the category. So if there is 10 posts in ...
1
vote
1answer
911 views

Using wp_list_categories like the the_category (showing just current categories of a post)

fromi'm using wp_list_categories to get an unordered list with headlines (on single.php inside the post-loop): <ul><?php wp_list_categories('title_li=0');?></ul> the thing is: i ...
1
vote
1answer
238 views

Get only one of the current categories

On post pages Im using the below code to display links to other posts from the current category. My problem is when the current post is in more than 1 category it will display posts from the first ...
1
vote
0answers
201 views

List only child categories within posts

I am using the_category() to display categories in my posts that are also filed in child-categories. Unfortunately this also displays the parent category which i would love to hide. Is there a way to ...
0
votes
2answers
468 views

Why is get_the_category() saying that I have two categories?

My post has only one category. The following code: $categories = get_the_category(); gives me this result: Array ( [0] => stdClass Object ( [term_id] => 22 ...
0
votes
3answers
102 views

Need help “sanitizing” a custom function that pulls category slug into body class

Not sure if "sanitizing" is really the correct phrase to use for this but it was the best one I could think of...anyways, here is the problem: My function works great like so... // add category id ...
0
votes
1answer
3k views

Test if post has a category

I need to display some HTML only if the post being displayed has a category - not a specific category, just any category at all. I tried if (!is_empty(get_the_category($post->ID))), but for some ...
0
votes
1answer
37 views

Output the text before category

I need to output the text before the_category. In result, it should be something like Posted on September 20, 2014 IN MyCategory Here I use the_time('F j, Y') and start from here I use ...
0
votes
2answers
482 views

Display post category in foreach loop

I am trying to display post category in a foreach loop. I have all the elements displaying properly except for the category. Here is my function: function my_get_display_author_posts() { global ...
0
votes
1answer
1k views

get_the_category listing in hierarchial order

Hello at the moment I'm wondering how I would be able to make this work to post in Hierarchical order within the post loop. <?php foreach ((get_the_category()) as $childcat) { ...
0
votes
2answers
187 views

Exclude one category from get_the_term_list

I want to exclude one of the categories from my posts, which will always be the same, named "documentaires" and with the ID 20. Here is the code : <?php echo get_the_term_list( get_the_ID(), ...
0
votes
1answer
109 views

Exclude category from get_the_category

I want to exclude a specific category from the loop, here's what I tried: Original code: // auto posts by cat if( $bawmrp_options['auto_posts'] == 'cat' || $bawmrp_options['auto_posts'] == ...
0
votes
1answer
63 views

Can't get Category link inside get_posts

I created a simple function to display the latest posts. Inside the function there is a conditional to display the post category. I found that to display the category name, using $category = ...
0
votes
1answer
50 views

Category Page Template - Can't get category ID

I am creating a category template that uses WP_query to get posts from my custom post type... <?php $query = new WP_Query( array( 'post_type' => array( 'mycpt' ), 'posts_per_page' => 5 ) ); ...
0
votes
2answers
1k views

How to exclude specific category from the get_the_category(); array

In my loop I've added: <?php $categories = get_the_category(); $separator = ' '; $output = ''; if($categories){ foreach($categories as $category) { $output .= '<span ...
0
votes
1answer
55 views

Get only X number of categories

How can i get only x number of categories using the_category. I triesd a few thing but none worked. I dont want to use get_the_category
0
votes
1answer
260 views

get_the_category_list open in parent window

I'm opening my posts in an iframe, and I'm using get_the_category_list to list post's categories. The problem is that when a user clicks on the category link, it opens in the iframe. How can I set the ...
0
votes
1answer
327 views

Finding and removing duplicates within WP Arrays

I'm looking to see if it's possible to find and remove duplicates from the arrays generated below. I've tried array_unique array_merge and they haven't worked. $category = get_the_category(); $tags ...
0
votes
1answer
2k views

Get 1st parent category id from post

I have this structure for my categories: Issue 4 - News - Supporting our troops - Breaking news <?php $category = get_the_category(); $parent = ...
0
votes
1answer
305 views

How to correctly display category's slug as a class?

I want to display category's slug as a class. I try to code and put this into functions.php add_filter('the_category', 'my_custom_get_the_category_list'); function ...
0
votes
1answer
347 views

Compare current post Category in select menu

i have done this many times but not via a form so i am getting a weird issues when trying to assign a "selected" based on the current post term id... Maybe the use of get_the_category and then ...
0
votes
1answer
928 views

Outside the loop Category name with link

I want to display the category Name by using category ID with link to category page (out side the loop). here is my code... <a href="<?php get_category_link('23'); ?>"><?php echo ...
0
votes
2answers
206 views

loop inside a loop : search for posts in the same category

Could someone tell me how i could make this work? i have a loop, and i would like to create another loop to find the other posts from the same category : but this does not work : <?php while ( ...
0
votes
1answer
194 views

Subcategory is displayed before Parent Category

I'm current using the following code to echo the categories of my post : <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?> So, for example, I have ...
0
votes
3answers
1k views

get_the_categories() but exclude children of “Uncategorized”

In this function, I need to exclude any categories from $categories which are children of "Uncategorized". function get_cats(){ $post_cats= array(); $categories = get_the_category(); ...
0
votes
2answers
905 views

Can't Get Parent and Child Categories of Custom Taxonomy to Display

I have a Custom Post Type set up with a Custom Taxonomy. For this Custom Taxonomy, I'm trying to figure out how to echo out the titles of the parent category and current child category within it. ...
0
votes
1answer
318 views

Better way to exclude category output for post/pages?

I always assumed there was a way to exclude certain categories from being output in the loop using get_the_category, the_category, or one of the term related functions. After looking around it seems ...
0
votes
1answer
13 views

Get category name from custom loop and echo it once

I have a magazine front page that updates with every issue, and the front page shows the current issue posts which are stickied. So for example, this month all the posts are in a category titlted ...
0
votes
1answer
68 views

Category with description and thumbnail

I am using the below codes to show all Parent Terms from a custom taxonomy with title and link on a page. But I want to show the parent term description, thumbnail and post count in it too. So how I ...
0
votes
0answers
15 views

Get link to top-level parent category of post

I am trying to create a link to the top-level parent of a given post. Many of my posts are in sub-categories. I intend to place a 'root category' image that links to the root category. I have tried ...
0
votes
1answer
27 views

Display the category name of a post that is in two different categories

I'm trying to get the category of a post that is in 2 different category. One category is always "Featured" and the other changes. I can only see the word Array() This is my code: <?php $args = ...
0
votes
1answer
54 views

the_category if/else statement

I need to do the following: The sense if I have a class dportfolio - show a category dportfolio. Otherwise show usual category. I use: if ( class_exists( 'DPortfolio' ) ) { echo ...
0
votes
1answer
45 views

How to get only the last child of category slug?

DESCRIPTION I want to get the name of the slug of the last child of the post's category. My categories of my posts represents cities and I am assigning them 3-4 level categories as continent, ...
0
votes
1answer
261 views

Display Categories or Subcategories with name & description in category.php in wordpress

I have the following issue for my customer. Can some suggest a possible solution to this issue? This website has Categories & Subcategories Cat1 -Subcat1 -Subcat2 -Subcat3 Cat2 -Subcat1 ...
0
votes
1answer
63 views

the_category() tag not styling HTML or CSS

I am having problems getting my the_category() template tag to style accordingly with the rest of my theme. I believe this is because the HTML isn't output the same way as the the_author() and ...
0
votes
0answers
14 views

Category Link to Post

I have a website with categories X, Y, Z...with the Search Everything plugin I can search based on the category name to return all the posts within a given category. I have the search results posts ...
0
votes
0answers
15 views

Category name from custom fields

I have a problem with getting category name. I was trying a few versions of code and I don't have any idea how to run it correctly. I have custom field (field type - taxonomy-category/ ...