Community Forums › Forums › Archived Forums › General Discussion › ? If specific category → don't show the category name
Tagged: php switch statement
- This topic has 5 replies, 3 voices, and was last updated 8 years, 5 months ago by
Matus.
-
AuthorPosts
-
July 13, 2017 at 10:31 am #209066
Matus
MemberHello everybody,
I have a PHP function (below), which I'm adding into functions.php file in my Genesis Sample Theme.
This code shows the name of the category in post and in my case it's outputted in entry header.
I already style it with CSS, but I need a little help with taking this code a step further.I'd like to add to this code condiction if is post filed under category named "Blog", this category won't be displayed.
But if is the post filed except the category "Blog" also in other categories, don't show just category "Blog".
So, my question is: How to do that?My code:
add_action ('genesis_entry_header' , 'category_name_link', 11); function category_name_link() { $categories = get_the_category(); if ( ! empty( $categories ) ) ?> <div class="category-custom"> <?php echo '<a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a>'; ?> </div> <?php }I'll appreciate any advice.
July 14, 2017 at 1:54 am #209086Brad Dalton
ParticipantJuly 14, 2017 at 3:50 am #209090Matus
MemberI'd like to display article category in post.
I don't want to use the standard edit method - StudioPress plugin Simple Edits.
What I don't like about this plugin I can choose only entry meta (above and below) article sections and there put some available shortcodes.My conditions:
1. Display post category above post title. This category should be also linked to its archive page. (When I click on category named Newsletter, I will be redirect to the Newsletter category archive page.)
2. If is article filed under category Blog, don't display just category Blog.
3. Don't display categories in pages (that's I think sure thing because pages don't have categories).July 14, 2017 at 4:09 am #209093Matus
MemberOne more think.
I don't want to display text "Filed under:" before categories.
Just the names of categories separated without comma (I'll style it so each category will have own border around itself).July 14, 2017 at 8:08 am #209107clintongallagher
MemberMy advice is about the switch statement. It is the way we solve problems like the one you're working with. Learn it. A couple of YouTube videos and you'll have it down pat.
July 27, 2017 at 1:57 am #209621Matus
MemberI resolved this problem. I created one category "Blog" and then every other category I set as subcategory to the Blog. In the posts I add categories I wanted except Blog. Because the Blog is the main category I was able to find all the posts in Blog page.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.