我试图将此代码更改为一个短代码,因为我现在使用的方法是调用整个文件,速度有点慢。
<?php
/**
* The template for displaying Archive pages.
*
* @package GeneratePress
*/
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly.
}
get_header();
?>
<div class="testttt">
<div class="containertest">
<div class="scroll">
<?php // Get the taxonomy\'s terms
$terms = get_terms(
array(
\'taxonomy\' => \'job_empresas\',
\'hide_empty\' => true,
)
);
// Check if any term exists
if ( ! empty( $terms ) && is_array( $terms ) ) {
// Run a loop and print them all
foreach ( $terms as $term ) { ?>
<div class="card">
<div class="card-image">
<img class="no-lazzy" src="<?php echo z_taxonomy_image_url($term->term_id, array(200, 200)); ?>"></a>
</div>
<div class="card-inner">
<h3 class="text text-title"><?php echo $term->name; ?></h3>
<div class="ofertas-company">Ofertas disponibles: <?php echo $term->count ?></div>
<input class="company-button" type="button" value="Ver ofertas" onclick="location.href=\'<?php echo esc_url( get_term_link( $term ) ) ?>\'">
</div>
</div>
<?php
}
} ?>
</div>
</div>
</div>
<script>
const scroll = document.querySelector(".scroll");
var isDown = false;
var scrollX;
var scrollLeft;
// Mouse Up Function
scroll.addEventListener("mouseup", () => {
isDown = false;
scroll.classList.remove("active");
});
// Mouse Leave Function
scroll.addEventListener("mouseleave", () => {
isDown = false;
scroll.classList.remove("active");
});
// Mouse Down Function
scroll.addEventListener("mousedown", (e) => {
e.preventDefault();
isDown = true;
scroll.classList.add("active");
scrollX = e.pageX - scroll.offsetLeft;
scrollLeft = scroll.scrollLeft;
});
// Mouse Move Function
scroll.addEventListener("mousemove", (e) => {
if (!isDown) return;
e.preventDefault();
var element = e.pageX - scroll.offsetLeft;
var scrolling = (element - scrollX) * 2;
scroll.scrollLeft = scrollLeft - scrolling;
});
</script>