Home › Forums › Pro Support › fetching custom post type
- This topic has 5 replies, 2 voices, and was last updated 2 years, 4 months ago by
elvin.
-
AuthorPosts
-
May 7, 2021 at 8:00 am #29975
Michelle
ParticipantI’d like to achieve this effect: https://sebastianfoster.com/artists, and was told it could be done with a bit of coding. Can someone help me with this?
I can create the post in any format, as long as we can get it to appear in the sidebar, or in a column of it’s own. Currently, these are product categories.
Thanks!
MichelleMay 9, 2021 at 7:15 pm #30045elvin
ModeratorHi there,
I remember answering this question.
And sorry about this but I believe I missed the context when I answered it. I thought the names of lists were posts lists of artists rather than a listing of categories.
WPSP plugin can’t list categories directly. My bad. If you bought the plugin for this, you can ask for a request for a refund.
But to help you out here’s something worth a try:
Before you start, here are things to consider:
Are the place labels going to be a taxonomy as well?
If it isn’t, you’ll need ACF or some sort of custom fields plugin to save the places associated with the artist name.
You then create your custom shortcode for this:
Example: A custom category listing with
artist_location
field displayed on the side.add_shortcode('category_listing','category_listing_with_location'); function category_listing_with_location(){ echo '<ul class="category-list">'; $categories = get_categories( array( 'orderby' => 'name', 'order' => 'ASC' ) ); foreach( $categories as $category ) { $acf_id = 'category_'.$category->term_id; $category_link = sprintf( '<a href="%1$s" alt="%2$s">%3$s</a> <span class="artist-location">%4$s</span>', esc_url( get_category_link( $category->term_id ) ), esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ), esc_html( $category->name ), get_field('artist_location',$acf_id), ); echo '<li class="category-list-item">' . $category_link . '</li> '; } echo '</ul>'; }
This is a PHP snippet – here’s how to add one – https://docs.generatepress.com/article/adding-php/
Note: we may need to style it with CSS to remove li styling.
example:
ul.category-list { list-style: none; }
Again, my bad.
May 10, 2021 at 7:24 am #30085Michelle
ParticipantHi Elvin!
Thanks so much for your reply! I can make these anything. They don’t have to be product categories. Should I make each artist a post? We can tackle the artist location later!
I’m guessing these will popup/appear in the sidebar? Can you point me in the direction of the instructions for this?Thanks!
MichelleMay 10, 2021 at 4:10 pm #30095elvin
ModeratorThanks so much for your reply! I can make these anything. They don’t have to be product categories. Should I make each artist a post? We can tackle the artist location later!
No need to change that. In fact, I think that’s already good. That’s how I’ll actually do it if it were up to me.
I’m guessing these will popup/appear in the sidebar? Can you point me in the direction of the instructions for this?
The PHP snippet I’ve provided allows you to use the shortcode
[category_listing]
which will display the category links + the ACF value for its location label.For this one, you can use it on any part of the site where shortcodes can run.
Note: As for ACF, please refer to this – https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
Here’s how to add PHP snippets – https://docs.generatepress.com/article/adding-php/
May 11, 2021 at 2:37 pm #30142Michelle
ParticipantHi Elvin!
I know just enough to mess this up. Can you email me privately? I’ve read on other topics there is a form or box for private information, but I can’t locate it.
Thanks!
MichelleMay 11, 2021 at 4:27 pm #30151elvin
ModeratorI’ve read on other topics there is a form or box for private information, but I can’t locate it.
GP support forums got one. This one doesn’t.
You can send us an email through our contact page if you prefer that. https://wpshowposts.com/contact/
-
AuthorPosts
- You must be logged in to reply to this topic.