Skip to content

Commit

Permalink
Stretch goal: refactoring content-single.php
Browse files Browse the repository at this point in the history
** Why are these changes being introduced:

* As we are now using content-single.php (and discovering that it was
  unused before), we are discovering that there is a pretty significant
  amount of debt in the template - unused conditionals, references to
  fields that no longer exist, etc. That made working with this template
  a bit trickier than needed because it wasn't clear what was needed.

** Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/pw-55

** How does this address that need:

* This refactors the template, removing unused variables, unused
  conditionals, etc. Full details are below.
* The mark_as_new field no longer exists, so that check is removed.
* The article category is not shown, and the old logic never actually
  displayed it - so we remove it entirely.
* There are no "features" or "updates" post types on the network, and
  the "exhibits" post type is not used on the News site - so those
  checks are also removed.
* The bespoke handling of event date and time information is removed in
  favor an existing partial that is used elsewhere in the theme. While
  we don't anticipate any event information to be displayed using this
  template (The DSpace@MIT tag has always been news articles written by
  our staf, and not event records imported from the central MIT
  calendar), this will protect us in the future if that changes.
* Whitespace is cleaned up, and references to $subtitle and $type
  variables that are never used are removed.

** Document any side effects to this change:

* None, unless I've missed a path somewhere in the theme where this
  partial is loaded somewhere other than tag.php. If that is the case,
  then there will likely be an impact in how content is rendered that
  I have not seen or considered.
  • Loading branch information
matt-bernhardt committed Sep 1, 2023
1 parent 1a08b23 commit 2c71816
Showing 1 changed file with 12 additions and 67 deletions.
79 changes: 12 additions & 67 deletions web/app/themes/mitlib-news/content-single.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,85 +8,30 @@

namespace Mitlib\News;

$category = get_the_category();
$type_post = get_post_type();
$subtitle;
$type;
$category = get_the_category();
$type_post = get_post_type();
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> data-category="<?php echo esc_attr( $category[0]->slug ); ?>">
<div class="title-page mySingle">
<?php if ( get_field( 'mark_as_new' ) === true ) : ?>
<span>New!</span>
<?php endif; ?>
<div class="title-page mySingle">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>


<div class="entry-meta">
<span class="author">
By <?php the_author_posts_link(); ?>
</span>
<span class="date-post">
<?php
echo ' on ';
the_date();
?>
</span>
<?php if ( has_category() ) : ?>
<span class="category-post-single">

<?php
$category = get_the_category();
?>




on <?php the_date(); ?>
</span>
<?php endif; ?>
</div><!-- .entry-meta -->
</div><!-- .title-page -->

<div class="entry-content mitContent">


<?php
the_content();
// Echo type of Feature, if Feature.
if ( 'features' === $type_post ) {
$type = get_field( 'feature_type' );
echo 'The feature type is' . esc_html( $type );
}
// Echo start/end dates, if they exist.
if ( 'exhibits' === $type_post || 'updates' === $type_post ) {
$date_start = get_field( 'date_start' );
$date_end = get_field( 'date_end' );
echo '<div>Start date is ' . esc_html( $date_start ) . '</div>';
echo '<div>End date is ' . esc_html( $date_end ) . '</div>';
}
?>


<?php

$date = \DateTime::createFromFormat( 'Ymd', get_field( 'event_date' ) );
// echo $date->format('d-m-Y');
// Check for events.
if ( 'post' == $type_post && 1 == get_field( 'is_event' ) ) {
?>

<div class="event"><span class="grey">Event date </span> <?php echo esc_html( $date->format( 'F, j Y' ) ); ?><span class="grey"> starting at</span> <?php echo esc_html( get_field( 'event_start_time' ) ); ?> <span class="grey">
<?php
if ( get_field( 'event_end_time' ) != '' ) {
?>
and ending at</span> <?php echo esc_html( get_field( 'event_end_time' ) ); } ?></div>


<?php
}
?>


</div><!-- .entry-content -->

<?php
the_content();

if ( 'post' == $type_post && 1 == get_field( 'is_event' ) ) {
get_template_part( 'inc/events' );
}
?>
</div>
</article><!-- #post-## -->

0 comments on commit 2c71816

Please sign in to comment.