LATEST ARTICLES

最新文章,
行业资讯与技术分享。

铝合金结构行业动态、技术解析与项目案例, 帮助您更全面地了解工业铝结构解决方案。

查看全部文章 →
'; var catHtml = catName ? '' + catName + '' : ''; return '' + '
' + imgHtml + catHtml + '' + svgClock + mins + ' 分钟' + '
' + '
' + '
' + '' + svgCal + date + '' + '' + '' + svgUser + authorName + '' + '
' + '

' + title + '

' + '

' + excerpt + '

' + '' + '
' + '
'; } /* 获取文章 */ function fetchPosts(){ /* ★ 自动获取当前域名,无需手动修改 ★ */ var base = window.location.origin; var apiUrl = base + '/wp-json/wp/v2/posts?per_page=6&_embed=true'; fetch(apiUrl) .then(function(res){ if(!res.ok) throw new Error('API error ' + res.status); return res.json(); }) .then(function(posts){ if(!posts || posts.length === 0){ showFallback(); return; } renderPosts(posts); }) .catch(function(){ showFallback(); }); } /* 渲染文章 */ function renderPosts(posts){ var grid = document.getElementById('blGrid'); var html = ''; posts.forEach(function(post, i){ /* 缩略图 */ var mediaUrl = ''; if(post._embedded && post._embedded['wp:featuredmedia'] && post._embedded['wp:featuredmedia'][0] && post._embedded['wp:featuredmedia'][0].source_url){ mediaUrl = post._embedded['wp:featuredmedia'][0].source_url; } /* 分类 */ var catName = ''; if(post._embedded && post._embedded['wp:term'] && post._embedded['wp:term'][0] && post._embedded['wp:term'][0][0]){ catName = post._embedded['wp:term'][0][0].name; } /* 作者 */ var authorName = '编辑部'; if(post._embedded && post._embedded['author'] && post._embedded['author'][0]){ authorName = post._embedded['author'][0].name; } html += buildCard(post, mediaUrl, catName, authorName, i * 80); }); grid.innerHTML = html; /* 触发入场动画 */ var obs = new IntersectionObserver(function(entries){ entries.forEach(function(entry){ if(entry.isIntersecting){ entry.target.classList.add('visible'); obs.unobserve(entry.target); } }); },{threshold:0.08}); grid.querySelectorAll('.bfu').forEach(function(el){ obs.observe(el); }); } /* API 不可用时显示提示 */ function showFallback(){ var grid = document.getElementById('blGrid'); grid.innerHTML = '
' + '

' + '暂时无法加载文章。
' + '请确认 WordPress REST API 已启用,
' + '或直接 访问文章列表页。' + '

' + '
'; } /* IntersectionObserver for header/footer */ var obs2 = new IntersectionObserver(function(entries){ entries.forEach(function(entry){ if(entry.isIntersecting){ entry.target.classList.add('visible'); obs2.unobserve(entry.target); } }); },{threshold:0.1}); document.querySelectorAll('.bfu').forEach(function(el){ obs2.observe(el); }); /* 启动 */ fetchPosts(); })();
大厂风格页脚 · 全屏 · 品牌Logo
搜索