Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make blog and case studies pull logos from Projects CPT -> Landscape #893

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class="wp-block-lf-case-study-overview <?php echo esc_html( $classes ); ?>">
} else {
// Insert spacer to maintain layout.
?>
<div style="height:5px" aria-hidden="true"
<div style="height:5px" aria-hidden="true"
class="wp-block-spacer case-study-overview__logo"></div>
<?php
}
Expand Down Expand Up @@ -154,7 +154,7 @@ class="wp-block-spacer case-study-overview__logo"></div>
</div>
</div>
<?php
endif;
endif;

if ( ! empty( $industries ) && ! is_wp_error( $industries ) ) :

Expand All @@ -181,7 +181,7 @@ class="wp-block-spacer case-study-overview__logo"></div>
</div>
</div>
<?php
endif;
endif;

if ( ! empty( $location ) && ! is_wp_error( $location ) ) :
?>
Expand All @@ -195,7 +195,7 @@ class="wp-block-spacer case-study-overview__logo"></div>
</div>
</div>
<?php
endif;
endif;

if ( ! empty( $cloud_types ) && ! is_wp_error( $cloud_types ) ) :

Expand All @@ -222,7 +222,7 @@ class="wp-block-spacer case-study-overview__logo"></div>
</div>
</div>
<?php
endif;
endif;

if ( ! empty( $product_type ) && ! is_wp_error( $product_type ) ) :
?>
Expand All @@ -235,7 +235,7 @@ class="wp-block-spacer case-study-overview__logo"></div>
</div>
</div>
<?php
endif;
endif;
?>
<div class="row">
<div class="col1">
Expand All @@ -245,30 +245,50 @@ class="wp-block-spacer case-study-overview__logo"></div>
</div>

<!-- Project area -->
<?php if ( ! empty( $projects ) && ! is_wp_error( $projects ) ) { ?>
<div class="case-study-overview__projects">
<p class="is-style-spaced-uppercase"><?php echo esc_html( $projects_used ); ?></p>
<div class="case-study-overview__project-icons">
<?php
foreach ( $projects as $project ) {
<?php
if ( ! empty( $projects ) && ! is_wp_error( $projects ) ) {
$project_slugs = wp_list_pluck( $projects, 'slug' );
$args = array(
'post_type' => 'lf_project',
'posts_per_page' => -1,
'post_status' => 'publish',
'post_name__in' => $project_slugs,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
?>
<div class="case-study-overview__projects">
<p class="is-style-spaced-uppercase"><?php echo esc_html( $projects_used ); ?></p>
<div class="case-study-overview__project-icons">
<?php
while ( $query->have_posts() ) {
$query->the_post();
$project_title = get_the_title();
$project_logo = get_post_meta( get_the_ID(), 'lf_project_logo', true );

if ( ! empty( $project_logo ) ) {
?>
<a class="case-study-overview__project-link" title="<?php echo esc_attr( 'View ' . $project_title ); ?>" href="<?php echo esc_url( '/projects/' . get_post_field( 'post_name', get_the_ID() ) ); ?>">
<img class="case-study-overview__project-icon" loading="lazy" decoding="async" height="60" width="70"
src="<?php echo esc_url( $project_logo ); ?>"
alt="<?php echo esc_attr( $project_title . ' logo' ); ?>">
</a>
<?php
}
}
?>
<div class="case-study-overview__project-icon">
<a title="View <?php echo esc_html( $project->name ); ?>" href="/projects/<?php echo esc_html( $project->slug ); ?>">
<img loading="lazy"
src="<?php echo esc_url( get_template_directory_uri() ) . '/images/projects/' . esc_html( $project->slug ) . '-icon-color.svg'; ?>"
alt="<?php echo esc_html( $project->name ); ?>">
</a>
</div>
<?php
}
?>
</div>
</div>
<?php
wp_reset_postdata();
}
?>
</div><!-- end of case-study-overview__projects -->
<?php
}
?>
<!-- Project area END -->

</div>
</div><!-- end of case-study-overview__meta -->
</div>
</section>
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public function display_plugin_setup_page() {
*/
public function validate( $input ) {

$this->tag_blog_posts_with_projects();
// This command used to tag all blog posts with projects when you save the settings in the admin.
// $this->tag_blog_posts_with_projects(); // phpcs:ignore.

$options = get_option( $this->plugin_name );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ public static function display_author( $the_post_id ) {
return;
}

// Create author byline.
$author_byline = 'By ' . $author;

return $author_byline;
return $author;
}

/**
Expand Down
82 changes: 62 additions & 20 deletions web/wp-content/themes/cncf-twenty-two/components/post-author.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,81 @@
<?php
/**
* Post Author area.
* Post Author area, only used on blog posts
*
* @package WordPress
* @subpackage cncf-theme
* @since 1.0.0
*/

$author_byline = Lf_Utils::display_author( get_the_ID() );
$projects_taxonomy = get_the_terms( get_the_ID(), 'lf-project' );
?>

<div class="post-author">
<p class="post-author__date">Posted on <?php the_date(); ?>

<?php
$author_image = get_post_meta( get_the_ID(), 'lf_post_guest_author_image', true );
$author_byline = Lf_Utils::display_author( get_the_ID() );
if ( $author_image ) {
Lf_Utils::display_responsive_images( $author_image, 'thumbnail', '7px', 'post-author__image', 'lazy', esc_html( $author_byline ) );
if ( $author_byline ) {
?>
<span
class="post-author__author">by <?php echo esc_html( $author_byline ); ?></span>
<?php
}
?>
<div>
</p>
<?php
if ( $projects_taxonomy && ! is_wp_error( $projects_taxonomy ) ) {
?>
<p
class="post-author__projects_title">CNCF projects highlighted in this post</p>
<div class="post-author__projects">
<?php
if ( $author_byline ) {
?>
<span
class="post-author__author"><?php echo esc_html( $author_byline ); ?></span>
<?php
$project_slugs = wp_list_pluck( $projects_taxonomy, 'slug' );
$args = array(
'post_type' => 'lf_project',
'name__in' => $project_slugs,
'posts_per_page' => -1,
'post_status' => 'publish',
);

$query = new WP_Query( $args );

$found_projects = array();

if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$current_slug = get_post_field( 'post_name', get_the_ID() );
$found_projects[ $current_slug ] = array(
'title' => get_the_title(),
'logo' => get_post_meta( get_the_ID(), 'lf_project_logo', true ),
);
}
wp_reset_postdata();
}
?>
<?php if ( $author_byline ) { ?>
<span class="post-author__date"><?php the_date(); ?></span>
<?php
} else {
?>
<span class="post-author__date">Posted on <?php the_date(); ?></span>
<?php

foreach ( $projects_taxonomy as $project ) {
if ( isset( $found_projects[ $project->slug ] ) ) {
$project_data = $found_projects[ $project->slug ];

if ( ! empty( $project_data['logo'] ) ) {
?>

<a class="post-author__projects_link" title="<?php echo esc_attr( 'Go to ' . $project->name ); ?>"
href="<?php echo esc_url( '/projects/' . $project->slug ); ?>">
<img class="post-author__projects_image" loading="eager" decoding="async" width="70" height="60"
src="<?php echo esc_url( $project_data['logo'] ); ?>"
alt="<?php echo esc_attr( $project->name . ' logo' ); ?>">
</a>
<?php
}
} else {
error_log( 'No project post found for slug: ' . $project->slug );
}
}
?>
</div>
</div>
<?php
}
?>
</div>
5 changes: 3 additions & 2 deletions web/wp-content/themes/cncf-twenty-two/components/title.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@
<?php
if ( is_singular( 'lf_case_study' ) || is_singular( 'lf_case_study_cn' ) ) {
?>
<!-- // case study title -->
<!-- // case study title - not used -->
<?php
} else {
?>
<h1 class="is-style-post-title" itemprop="headline"><?php the_title(); ?>
<h1 class="is-style-post-title" itemprop="headline">
<?php the_title(); ?>
</h1>
<?php
}
Expand Down

This file was deleted.

This file was deleted.

Loading