- This topic has 32 replies, 3 voices, and was last updated 4 years, 6 months ago by
David.
-
AuthorPosts
-
September 21, 2021 at 10:41 am #1938251
Dan
Hi,
I have a custom post type which has some custom fields in it. One of them is called ‘Short description’.
In the archive page which displays the list of post in that CPT category I would like to display under the post the ‘short description’ which is a custom field.
currently, it is not displaying.
You can see the setting in the screenshot:
https://www.dropbox.com/s/wx0rrsz961n2ybx/post_meta.jpg?dl=0And the output:
https://www.dropbox.com/s/b8cdil8l0mhtv7m/output.jpg?dl=0Also, I would like to make all archive pages (categories and tags) of this custom post type display in 3 columns. can that be done via the block elements, or will it need some custom CSS?
Thanks!
DanSeptember 21, 2021 at 11:33 am #1938282Ying
StaffCustomer SupportHi Dan,
Just to confirm is the Custom filed called
short descriptionorshort_description?Please make sure the names you entered are the same.
And to add column to your custom post type archive, please check this guide:
https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-typeLet me know if you need further assistance 🙂
September 21, 2021 at 11:41 am #1938288Dan
Hi Ying,
Thanks for replying.
the custom field isshort_descriptionRegarding the columns, I added this snippet
add_filter( 'generate_blog_columns','tu_portfolio_columns' ); function tu_portfolio_columns( $columns ) { if ( is_post_type_archive( 'catalog' ) ) { return 33; } return $columns; }But it’s still 1 column
Dan
September 21, 2021 at 11:43 am #1938293Dan
just mentioning that the archive page is built with block elements.
See screenshot:
https://www.dropbox.com/s/1bz43p3ig99xv6s/content-grid.jpg?dl=0Dan
September 21, 2021 at 11:53 am #1938300Ying
StaffCustomer SupportDoes your blog has 3 columns set already? If so, you only need this PHP snippet:
https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-typeIf your blog has different columns number, then you’ll need this PHP snippet as well:
https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columnsFor the custom filed, your settings in the element looks right, just wondering what’s the content highlighted in red?
https://www.screencast.com/t/AAVJ7lXk4RLet me know.
September 21, 2021 at 11:56 am #1938301Dan
I think I’ll figure out the columns with custom CSS, thanks.
The content in red it the post’s title.September 21, 2021 at 12:05 pm #1938304Dan
in the post itself, this is the ‘short_description’ custom field.
(it’s part of an ACF block):
https://www.dropbox.com/s/gqvmoucivm047y0/short-description.jpg?dl=0Dan
September 21, 2021 at 12:17 pm #1938311Ying
StaffCustomer SupportNot sure why it doesn’t work by looking at the screenshots.
Can you provide access to admin so we can have look at the back end?
September 21, 2021 at 12:27 pm #1938322Dan
The custom field is from an ACF within a block, could that influence the output?
The site is still in local dev, I’ll upload to staging in a few days.Another related question, I would like to make the main category (archive) page a static one, so I tried with elements but the output isn’t right, it still creates some sort of loop (when using the ‘content template’ element type).
Would it be correct to create a ‘page header’ element, set the location to the custom post type archive, create the blocks I want to see and then hide the loop with CSS?September 21, 2021 at 1:05 pm #1938354Ying
StaffCustomer SupportThe site is still in local dev, I’ll upload to staging in a few days.
We can have a look then, let us know.
Would it be correct to create a ‘page header’ element, set the location to the custom post type archive, create the blocks I want to see and then hide the loop with CSS?
Doesn’t sound right, in this way, all the content is still loading, not great for your site performance.
Give this PHP snippet a try:
https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/Let’s say the category is called ‘event’ , you need to create a new static page named ‘event’, put everything you want to show in this static page.
Then set the Category base to
.at settings > permalinks.With the PHP snippet, the default category archive page will be replaced by the static page.
September 21, 2021 at 1:16 pm #1938365Dan
Thanks, Yes, I thought there may be a better way.
But I would like the static page be for the main archive of the CPT not for specific categories.
Is it possible to check if it’s the archive of the CPT and then replace it with the static page (without causing issues for other categories and the default WP posts and categories)September 21, 2021 at 1:30 pm #1938383Ying
StaffCustomer SupportIn this case, you can try something like this:
function archive_to_custom_archive() { if( is_post_type_archive( 'event' ) ) { wp_redirect( home_url( '/events/' ), 301 ); exit(); } } add_action( 'template_redirect', 'archive_to_custom_archive' );September 21, 2021 at 1:31 pm #1938384Dan
ok, so that would be a simple redirect to the static page?
September 21, 2021 at 1:55 pm #1938401Ying
StaffCustomer SupportYes.
September 21, 2021 at 1:56 pm #1938402Dan
ok, thanks
-
AuthorPosts
- You must be logged in to reply to this topic.