Add pledge archive templates

This commit is contained in:
Kelly Dwan 2019-10-09 14:38:44 -04:00
parent 3847e83cf3
commit b210abe340
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D
3 changed files with 125 additions and 0 deletions

View file

@ -94,6 +94,12 @@
<exclude name="WordPress.PHP.DevelopmentFunctions.error_log_print_r" />
</rule>
<!-- Ignore the CPT template filename, since it is based on the CPT name, and can't change. -->
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>*/template-parts/content-5ftf_pledge.php$</exclude-pattern>
<exclude-pattern>*/archive-5ftf_pledge.php$</exclude-pattern>
</rule>
<rule ref="WordPress-Docs">
<!-- If files/variables are given descriptive names like they should be, then an explicit description is usually unnecessary, so leave this as a judgement call. -->
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />

View file

@ -0,0 +1,46 @@
<?php
namespace WordPressdotorg\Five_for_the_Future\Theme;
// If we don't have any posts to display for the archive, then send a 404 status. See #meta4151.
if ( ! have_posts() ) {
status_header( 404 );
nocache_headers();
}
get_header(); ?>
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
</header><!-- .page-header -->
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', get_post_type() );
endwhile;
the_posts_pagination();
?>
<?php else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</main><!-- #main -->
<?php
get_footer();

View file

@ -0,0 +1,73 @@
<?php
/**
* Display pledge data in the archive & single view.
*/
namespace WordPressdotorg\Five_for_the_Future\Theme;
use WordPressDotOrg\FiveForTheFuture\PledgeMeta;
$data = array();
foreach ( PledgeMeta\get_pledge_meta_config() as $key => $config ) {
$data[ $key ] = get_post_meta( get_the_ID(), PledgeMeta\META_PREFIX . $key, $config['single'] );
}
$data['org-logo'] = 'https://5ftf.test/content/uploads/2019/10/uh.png';
// @todo Get real contributors from the post.
$contributors = array();
$count = count( $contributors );
$content = apply_filters( 'the_content', $data['org-description'] );
$contributor_title = sprintf(
esc_html(
_n( '%1$s has pledged %2$d contributor', '%1$s has pledged %2$d contributors', $count, 'wordpressorg' )
),
wp_kses_post( get_the_title() ),
intval( $count )
);
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-image">
<?php if ( $data['org-logo'] ) : ?>
<div class="entry-image__logo">
<?php printf( '<img src="%s" />', esc_url( $data['org-logo'] ) ); ?>
</div>
<?php else : ?>
<div class="entry-image__placeholder"></div>
<?php endif; ?>
</div><!-- .post-thumbnail -->
<header class="entry-header">
<?php if ( is_singular() ) : ?>
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
<?php else : ?>
<?php the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
<?php endif; ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php
echo wp_kses_post( $content );
?>
<div class="pledge-contributors">
<?php /* phpcs:ignore -- escaped above */ ?>
<h3><?php echo $contributor_title ?></h3>
<?php foreach ( $contributors as $contrib_email ) : ?>
<span class="pledge-contributor__avatar">
<?php echo get_avatar( $contrib_email, 30, 'blank' ); ?>
</span>
<?php endforeach; ?>
</div><!-- .pledge-contributors -->
</div><!-- .entry-content -->
</article><!-- #post-## -->