Alpha Plus
Forum Replies Created
-
Forum: Plugins
In reply to: [Storefront Site Logo] Logo not displaying with screen sizeThanks for getting back to me.
Unfortunately the site is in ‘coming soon’ mode so I can’t share a link. I was able to sort it out with a bit of extra CSS and some
!important
tags.-Karl
Forum: Fixing WordPress
In reply to: Finding the category slug with phpI ended up working it out. I used this piece of code here:
<?php //Get campaign category name and slug $terms = get_the_terms( $post->ID, 'download_category' ); if ( $terms && ! is_wp_error( $terms ) ) : $categories = array(); $slugs = array(); foreach ( $terms as $term ) { $categories[] = $term->name; $slugs[] = $term->slug; } $category = join( " / ", $categories ); $slug = join( " / ", $slugs ); endif; ?>
I echoed the above like this:
<a href="/about/<? echo $slug ?>">About</a> <a href="/campaigns/category/<? echo $slug ?>">More from <? echo $category ?></a>
NOTE: This will only work when the post is assigned to one category.
Forum: Fixing WordPress
In reply to: Finding the category slug with phpThanks vtxyzzy.. The problem is that it’s a custom post type, so all the get_category commands don’t work. Apparently they only work with the regular blog posts.
The get_term commands are what I think I’m supposed to be using, but I still can’t get it to spit out a ‘slug’
Forum: Themes and Templates
In reply to: get_terms not working on custom post typeOkay.. that problem is solved.. I needed to use
download_category
instead ofcategory
because it was a custom post type.Right now the code looks like this:
<?php $terms = get_the_terms( $post->ID, 'download_category' ); if ( $terms && ! is_wp_error( $terms ) ) : $category_links = array(); foreach ( $terms as $term ) { $category_links[] = $term->name; } $category = join( ", ", $category_links ); endif; ?>
Then for displaying what I want to happen, I have an if statement.
<?php if (has_term( 'Category Name', 'download_category' ) ) : echo ( '<img src="/image/path/' . $category . '.png" /> ...Insert extra text and links under image specific to each category...' ); elseif (has_term( 'Category Name', 'download_category' ) ) : echo ( '<img src="/image/path/' . $category . '.png" />' );
And it just continues for each category. I am hoping there is a simpler way…
The way I am hoping it can work is this:
1. Look up category and define.
2. The picture and text will read the same for each category – just with different sources and links – each of which could be set to use the$category
as part of the link, as in the image path above. Example:<a href="https://example.com/about/' . $category . '/">About Category Name</a>
The problem with this is that most category names have a space and use capital letters — Not url friendly… I want to know if there is a way to use the category slug instead.
Thanks for any help!