Skip to content

Instantly share code, notes, and snippets.

@johnnya23
Last active February 7, 2022 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnnya23/ce8f84a758c00e36a5da538294adf335 to your computer and use it in GitHub Desktop.
Save johnnya23/ce8f84a758c00e36a5da538294adf335 to your computer and use it in GitHub Desktop.
Create custom display for native archives
body.archive .post, body.blog .post {
margin: 0;
padding: 1px;
border: none;
}
body.archive .post img, body.blog .post img {
width: 100%;
}
@media (min-width: 768px) {
body.archive .post, body.blog .post {
width: 33.33%;
float: left;
}
body.archive .post:nth-of-type(3n+1), body.blog .post:nth-of-type(3n+1) {
clear: both;
}
body.archive .post .jma-title-content-wrap, body.blog .post .jma-title-content-wrap {
font-size: 24px;
}
}
<?php
function jma_kid_template_redirect()
{
if (is_archive('post') || is_home()) {
remove_all_actions('genesis_entry_header');
remove_all_actions('genesis_entry_content');
add_action('genesis_entry_header', 'jma_kid_genesis_entry_header');
}
}
add_action('template_redirect', 'jma_kid_template_redirect');
function jma_kid_genesis_entry_header()
{
require('image-bg-grid.php');
}
<?php
$base_class = esc_attr($extra_attr['block_name']);
$class_array = explode(' ', $attributes['className']);
$href = get_permalink();
$target = '_self';
//optional acf integration for alternate link
if (function_exists('get_field') && get_field('image_link', $post->ID)) {
$href = get_field('image_link', $post->ID);
$rel = ' rel="bookmark noopener noreferrer"';
$target = '_blank';
}
$x = '<div class="jma-inner-wrap ' . esc_attr($base_class . ' ' . $attributes['className']) . '" style="position:relative">';
$x .= '<div class="jma-image">';
$x .= '<a href="' . $href . '" target="' . $target . '"' . $rel. '>';
$x .= get_the_post_thumbnail($post, 'jma-gbs-gird');
$x .= '</a>';
$x .= '</div>';
$x .= '<div class="jma-title-content-wrap" style="position:absolute;width:90%;text-align:center;line-height:110%;padding:3px;background:rgba(255,255,255,0.65);top:50%;left:50%;transform:translate(-50%,-50%);pointer-events:none;">';
$x .= '<span class="jma-title">' . wp_kses_post(get_the_title($post)) . '</span>';
if (strpos($attributes['className'], 'with-excerpt') !== false) {
$x .= '<div class="jma-content">';
$x .= wp_kses_post(get_the_excerpt());
$x .= '</div>';
}
$x .= '</div>';
$x .= '</div>';
echo $x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment