Hello,
In my WordPress blog, the theme uses the “destacado” (featured) tag to feature the first 4 posts with this tag in the top section. I want to replicate this behavior in Frontity and I think I got it right but I want to make sure it is the correct way or if there’s a better form.
What I got so far in my component:
import React, {useEffect} from "react"
import { connect, styled } from "frontity"
import Link from "@frontity/components/link"
const IndexBody = ({state, actions}) => {
useEffect(()=>{
actions.source.fetch("/tag/destacado")
}, []);
const data = state.source.get("/tag/destacado")
return (
<>
<DestaList isReady={data.isReady}>
{data.isReady && data.items.map((item) => {
const post = state.source[item.type][item.id]
return (
<Link key={item.id} link={post.link}>
{post.title.rendered}
<br/>
</Link>
)
})}
</DestaList>
</>
)
}
export default connect(IndexBody)
const DestaList = styled.div`
height: 300px;
background-color: ${(props) => (props.isReady ? "lightseagreen" : "maroon")};
`
The box starts with the maroon background, gets populated and turns light sea green, so I know the code works, but is it the best way?
Also, how can I just ask for the first 4 posts instead of the default 10?
Thanks!