Skip to content

Commit

Permalink
Merge pull request #47 from pattyok/expand
Browse files Browse the repository at this point in the history
updates to taxonomy block
  • Loading branch information
pattyok authored Dec 4, 2024
2 parents 784fb27 + c88689b commit 059cd47
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 22 deletions.
24 changes: 24 additions & 0 deletions build/taxonomy-archive-links/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"type": "boolean",
"default": false
},
"excludeChildTerms": {
"type": "boolean",
"default": false
},
"className": {
"type": "string"
},
Expand All @@ -62,6 +66,26 @@
"listLabel": {
"type": "string",
"default": ""
},
"archiveType": {
"type": "string",
"default": "wordpress"
},
"archivePage": {
"type": "string",
"default": ""
},
"archiveFacet": {
"type": "string",
"default": ""
},
"tileImageField": {
"type": "string",
"default": ""
},
"tileImageStyle": {
"type": "string",
"default": "icon"
}
},
"supports": {
Expand Down
2 changes: 1 addition & 1 deletion build/taxonomy-archive-links/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '668476cde0271b785599');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '28073c9e1afa613f42a7');
2 changes: 1 addition & 1 deletion build/taxonomy-archive-links/index.js

Large diffs are not rendered by default.

55 changes: 47 additions & 8 deletions build/taxonomy-archive-links/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@

global $post;
$term_list = '';
$list_style = $attributes['showBullets'] == true ? '' : 'no-bullets ';
$list_style .= $attributes['displayAs'] == 'inline' ? 'list-inline ' : '';
$list_style .= 'separator-' . $attributes['separator'];
if ( $attributes['displayAs'] == 'tile' ) {
$list_style = 'tile-list no-bullets';
} else {
$list_style = $attributes['showBullets'] == true ? '' : 'no-bullets ';
$list_style .= $attributes['displayAs'] == 'inline' ? 'list-inline ' : '';
$list_style .= 'separator-' . $attributes['separator'];
}

$aria_title = $attributes['listLabel'] ? $attributes['listLabel'] : 'Taxonomy List for ' . $attributes['taxonomySelected'];
if ( true == $attributes['relevantToPost'] ) {
$terms = get_the_terms( $post->ID, $attributes['taxonomySelected'] );
Expand All @@ -19,19 +24,53 @@
'orderby' => $attributes['sortBy'],
'order' => $attributes['order'],
);
if ( $attributes['excludeChildTerms'] ) {
$args['parent'] = 0;
}
$terms = get_terms( $args );
}

if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_list = '<ul class="term-archive ' . $list_style . '" aria-label="' . $aria_title . '">';
foreach ( $terms as $term ) {
$term_link_url = apply_filters( 'ck_tax_archive_term_link', get_term_link( $term ), $term, $post );
$term_link_text = apply_filters( 'ck_tax_archive_term_text', $term->name, $term, $post );
$term_link_url = '';
$term_link_text = $term->name;
if ( true == $attributes['linkToCategory'] ) {
$term_link = '<a href="' . esc_url( $term_link_url ) . '" alt="' . esc_attr( sprintf( __( 'View all items filed under %s', 'my_localization_domain' ), $term->name ) ) . '">' . $term_link_text . '</a>';
if ( 'wordpress' == $attributes['archiveType'] ) {
$term_link_url = get_term_link( $term );
} else if ( 'facetwp' == $attributes['archiveType'] ) {
$term_link_url = add_query_arg(
array(
$attributes['archiveFacet'] => $term->slug,
),
$attributes['archivePage']);
}
}
$term_content = '';
$term_icon = '';
$tile_hover = '';
if ( $attributes['displayAs'] == 'tile' ) {
$img_field = $attributes['tileImageField'];
if ( ! empty( $img_field ) ) {
$term_image = get_field( $img_field, $term );
$img_style = $attributes['tileImageStyle'];
if ( ! empty( $term_image ) ) {
$term_icon = wp_get_attachment_image( $term_image, array('600', '600'), "", array( "class" => $img_style ) );
}
}
$tile_hover = '<div class="tile-hover"><span>' . esc_html( $term->description ) . '</span></div>';
}

$term_link_url = apply_filters( 'ck_tax_archive_term_link', $term_link_url, $term, $post );
$term_link_text = apply_filters( 'ck_tax_archive_term_text', $term->name, $term, $post );
if ( empty( $term_link_url ) ) {
$term_content .= esc_html( $term_link_text );
} else {
$term_link = $term_link_text;
$term_content .= '<a href="' . esc_url( $term_link_url ) . '">' . $term_icon . esc_html( $term_link_text ) . $tile_hover . '</a>';
}
$term_list .= '<li>' . $term_link . '</li>';

//$term_content .= $tile_hover;
$term_list .= '<li>' . $term_content . '</li>';
}
$term_list .= '</ul>';
}
Expand Down
2 changes: 1 addition & 1 deletion build/taxonomy-archive-links/style-index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion carkeek-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Primary Branch: main
* Description: Series of blocks designed to work with this site's custom Theme
* Author: Patty O'Hara
* Version: 3.2.36
* Version: 3.2.37
* Author URI https://carkeekstudios.com/
* Text Domain: carkeek-blocks
*/
Expand Down
1 change: 0 additions & 1 deletion includes/class-carkeekblocks-custom-archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ function( $t ) {
$query = new WP_Query( $args );
}


$posts = '';

if ( true == $related && true == $attributes['fillTheSlots'] && -1 !== $attributes['numberOfPosts'] ) {
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove
2. This is the second screen shot

== Changelog ==
= 3.2.37 =
* Release 3.2.37 = 12/04/24
* Made some updates to the taxonomy block to support a link tile style taxonomy layout
= 3.2.36 =
* Release 3.2.35 = 10/25/24
* Added a expand/collapse button block.
Expand Down
24 changes: 24 additions & 0 deletions src/taxonomy-archive-links/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"type": "boolean",
"default": false
},
"excludeChildTerms": {
"type": "boolean",
"default": false
},
"className": {
"type": "string"
},
Expand All @@ -58,6 +62,26 @@
"listLabel": {
"type": "string",
"default": ""
},
"archiveType": {
"type": "string",
"default": "wordpress"
},
"archivePage": {
"type": "string",
"default": ""
},
"archiveFacet": {
"type": "string",
"default": ""
},
"tileImageField": {
"type": "string",
"default": ""
},
"tileImageStyle": {
"type": "string",
"default": "icon"
}
},
"supports": {
Expand Down
78 changes: 77 additions & 1 deletion src/taxonomy-archive-links/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ function postsInspector( props ){
displayAs,
separator,
showBullets,
listLabel
listLabel,
archiveType,
archivePage,
archiveFacet,
tileImageField,
tileImageStyle,
excludeChildTerms

} = attributes;


Expand Down Expand Up @@ -105,6 +112,13 @@ function postsInspector( props ){
onChange={value =>
setAttributes({ linkToCategory: value })
}
/>
<ToggleControl
label="Exclude Child Terms"
checked={ excludeChildTerms }
onChange={value =>
setAttributes({ excludeChildTerms: value })
}
/>
</PanelBody>
<PanelBody title={__("Layout Style", "carkeek-blocks")}>
Expand All @@ -125,6 +139,7 @@ function postsInspector( props ){
options={[
{ label: __("Vertical List"), value: "list"},
{ label: __("Horizontal (inline) List"), value: "inline"},
{ label: __("Link Tile"), value: "tile"},
]}
value={displayAs}
/>
Expand Down Expand Up @@ -153,8 +168,69 @@ function postsInspector( props ){
}
/>
}
</PanelBody>
{ displayAs === 'tile' &&

<PanelBody title={__("Tile Settings", "carkeek-blocks")}>
<TextControl
label="Image Field"
value={ tileImageField }
onChange={value =>
setAttributes({ tileImageField: value })
}
/>
<SelectControl
label={__("Image Style", "carkeek-blocks")}
onChange={value =>
setAttributes({
tileImageStyle: value
})
}
options={[
{ label: __("Icon"), value: "icon"},
{ label: __("Cover"), value: "cover"},
]}
value={tileImageStyle}
/>
</PanelBody>
}
{ linkToCategory &&
<PanelBody title={__("Archive Settings", "carkeek-blocks")}>
<SelectControl
label={__("Archive Type", "carkeek-blocks")}
onChange={value =>
setAttributes({
archiveType: value
})
}
options={[
{ label: __("WordPress"), value: "wordpress"},
{ label: __("FacetWP"), value: "facetwp"},
]}
value={archiveType}
/>
{ archiveType === 'facetwp' &&
<>
<TextControl
label="Archive URL"
value={ archivePage }
onChange={value =>
setAttributes({ archivePage: value })
}
/>
<TextControl
label="Taxonomy Facet"
value={ archiveFacet }
onChange={value =>
setAttributes({ archiveFacet: value })
}
/>
</>
}

</PanelBody>
}




Expand Down
55 changes: 47 additions & 8 deletions src/taxonomy-archive-links/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@

global $post;
$term_list = '';
$list_style = $attributes['showBullets'] == true ? '' : 'no-bullets ';
$list_style .= $attributes['displayAs'] == 'inline' ? 'list-inline ' : '';
$list_style .= 'separator-' . $attributes['separator'];
if ( $attributes['displayAs'] == 'tile' ) {
$list_style = 'tile-list no-bullets';
} else {
$list_style = $attributes['showBullets'] == true ? '' : 'no-bullets ';
$list_style .= $attributes['displayAs'] == 'inline' ? 'list-inline ' : '';
$list_style .= 'separator-' . $attributes['separator'];
}

$aria_title = $attributes['listLabel'] ? $attributes['listLabel'] : 'Taxonomy List for ' . $attributes['taxonomySelected'];
if ( true == $attributes['relevantToPost'] ) {
$terms = get_the_terms( $post->ID, $attributes['taxonomySelected'] );
Expand All @@ -19,19 +24,53 @@
'orderby' => $attributes['sortBy'],
'order' => $attributes['order'],
);
if ( $attributes['excludeChildTerms'] ) {
$args['parent'] = 0;
}
$terms = get_terms( $args );
}

if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_list = '<ul class="term-archive ' . $list_style . '" aria-label="' . $aria_title . '">';
foreach ( $terms as $term ) {
$term_link_url = apply_filters( 'ck_tax_archive_term_link', get_term_link( $term ), $term, $post );
$term_link_text = apply_filters( 'ck_tax_archive_term_text', $term->name, $term, $post );
$term_link_url = '';
$term_link_text = $term->name;
if ( true == $attributes['linkToCategory'] ) {
$term_link = '<a href="' . esc_url( $term_link_url ) . '" alt="' . esc_attr( sprintf( __( 'View all items filed under %s', 'my_localization_domain' ), $term->name ) ) . '">' . $term_link_text . '</a>';
if ( 'wordpress' == $attributes['archiveType'] ) {
$term_link_url = get_term_link( $term );
} else if ( 'facetwp' == $attributes['archiveType'] ) {
$term_link_url = add_query_arg(
array(
$attributes['archiveFacet'] => $term->slug,
),
$attributes['archivePage']);
}
}
$term_content = '';
$term_icon = '';
$tile_hover = '';
if ( $attributes['displayAs'] == 'tile' ) {
$img_field = $attributes['tileImageField'];
if ( ! empty( $img_field ) ) {
$term_image = get_field( $img_field, $term );
$img_style = $attributes['tileImageStyle'];
if ( ! empty( $term_image ) ) {
$term_icon = wp_get_attachment_image( $term_image, array('600', '600'), "", array( "class" => $img_style ) );
}
}
$tile_hover = '<div class="tile-hover"><span>' . esc_html( $term->description ) . '</span></div>';
}

$term_link_url = apply_filters( 'ck_tax_archive_term_link', $term_link_url, $term, $post );
$term_link_text = apply_filters( 'ck_tax_archive_term_text', $term->name, $term, $post );
if ( empty( $term_link_url ) ) {
$term_content .= esc_html( $term_link_text );
} else {
$term_link = $term_link_text;
$term_content .= '<a href="' . esc_url( $term_link_url ) . '">' . $term_icon . esc_html( $term_link_text ) . $tile_hover . '</a>';
}
$term_list .= '<li>' . $term_link . '</li>';

//$term_content .= $tile_hover;
$term_list .= '<li>' . $term_content . '</li>';
}
$term_list .= '</ul>';
}
Expand Down
Loading

0 comments on commit 059cd47

Please sign in to comment.