- This topic has 3 replies, 2 voices, and was last updated 4 years, 6 months ago by Tom.
-
AuthorPosts
-
October 4, 2019 at 5:19 pm #1026606Walter
Hello,
First of all I love the support you provide Tom and LOOVE Generate Press. So here’s my dilemma. I used a code similar to what you provided in this thread.
With the code below, it applies the function to ALL my archive pages instead of just e_editions. I can’t figure out what I’m doing wrong but I’m no php expert, just no enough to tinker and make adjustments.
The idea is to have the featured image on the e_editions cpt link to the acf field url I’ve created (get_field(‘download_file’)).
Note: I created single-e_editions.php, archive-e_editions.php, and content-E_Editions.php for the CPT. The archive-e_editions.php has this code: get_template_part( ‘content-E-Editions’, get_post_format() ); Maybe I messed something up there? Any help would be much appreciated.
//Give me styling control over the featured image thumbs in cpt
add_filter( ‘generate_single_featured_image_output’, ‘tu_change_cpt_image_structure’ );
add_filter( ‘generate_featured_image_output’, ‘tu_change_cpt_image_structure’ );
function tu_change_cpt_image_structure( $output ) {
if ( is_archive(‘e_editions’) ) {
$output = sprintf( // WPCS: XSS ok.
‘‘,
esc_url( get_field(‘download_file’) ),
get_the_post_thumbnail(
get_the_ID(),
apply_filters( ‘generate_page_header_default_size’, ‘full’ ),
array(
‘itemprop’ => ‘image’,
)
)
);
}echo $output;
}October 4, 2019 at 5:24 pm #1026612WalterSorry I didn’t put snippet into code brackets. Here you go.
//Give me styling control over the featured image thumbs in cpt add_filter( 'generate_single_featured_image_output', 'tu_change_cpt_image_structure' ); add_filter( 'generate_featured_image_output', 'tu_change_cpt_image_structure' ); function tu_change_cpt_image_structure( $output ) { if ( is_archive('e_editions') ) { $output = sprintf( // WPCS: XSS ok. '<div class="post-image"> <a href="%1$s"> %2$s </a> </div>', esc_url( get_field('download_file') ), get_the_post_thumbnail( get_the_ID(), apply_filters( 'generate_page_header_default_size', 'full' ), array( 'itemprop' => 'image', ) ) ); } echo $output; }
October 4, 2019 at 6:17 pm #1026618WalterUPDATE:I figured it out! Thank you anyways! Here what I did in case anyone has the same need:
//Give me styling control over the featured image thumbs in cpt add_filter( 'generate_single_featured_image_output', 'tu_change_cpt_image_structure' ); add_filter( 'generate_featured_image_output', 'tu_change_cpt_image_structure' ); function tu_change_cpt_image_structure( $output ) { if ( is_post_type_archive('e_editions') ) { $output = sprintf( // WPCS: XSS ok. '<div class="post-image"> <a href="%1$s"> %2$s </a> </div>', esc_url( get_field('download_file') ), get_the_post_thumbnail( get_the_ID(), apply_filters( 'generate_page_header_default_size', 'full' ), array( 'itemprop' => 'image', ) ) ); } echo $output; }
October 4, 2019 at 6:55 pm #1026623TomLead DeveloperLead DeveloperGlad you got this sorted out 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.