Frontity Tutorial
  • 👋Welcome
  • ✔️Checking your progress
  • 1️⃣ Creating a custom theme
    • Create a Frontity Project
    • Create a Theme Package
    • Modify the <Root> component
    • Connect the <Root> component to the state
  • 2️⃣ Adding a menu
    • Use the <Link> component
  • 3️⃣ Displaying posts
    • Understanding the Frontity state
    • Display the list of posts
    • Display the post content
    • Display posts and pages separately
    • Formatting the date
  • 4️⃣ Adding styling
    • Global styles
    • Styled components
    • Styling the links
    • Styling the post info
    • Add dynamic styling
  • 5️⃣ Adding behaviour
    • Use 'state' and 'actions'
    • Add pagination
  • 6️⃣ Custom Post Types
    • Add support for Custom Post Types
  • 7️⃣ Finishing touches
    • Add a <Loading> component
    • Add a 404 page
    • Use the <html2react> component
    • SEO and head tags
    • Other things to do
  • 8️⃣ Deploying the project
    • Deploy to Vercel
  • 9️⃣ Next Steps
    • Learning resources
    • Getting help and support
    • Contributing to Frontity
Powered by GitBook
On this page
  • 1. Show the post excerpt on the listing pages
  • 2. Display the destination CPT listing differently from the standard posts
  • 3. Use a single component for both posts and pages
  • 4. Create a destination component to display the custom post type differently
  • 5. Put the <Header> in its own component
  • 6. Show the featured image
  • 7. Display the destination listing by region
  1. 7️⃣ Finishing touches

Other things to do

PreviousSEO and head tagsNext8️⃣ Deploying the project

Last updated 4 years ago

By this stage you have a fully-functioning and full-featured Frontity site with a custom theme, and your knowledge of working with Frontity has progressed by leaps and bounds.

You're undoubtedly keen to try out your new Frontity dev skills, so here are some ideas for other features that can be added to the theme that we've been working on. Try some of them out on your own and see how you get on.

☝️ Remember that you can always ask in the if you get stuck whilst working on any of these ideas. You'll find a friendly community of developers who are happy to help out and answer any questions you might have.

1. Show the post excerpt on the listing pages

At the moment the listing pages just show the title of the post as a clickable link. Why not show the excerpt below each post title and style it to suit the rest of the site. How about adding a 'Read more...' link after each excerpt.

HINT — The excerpt can be retrieved from the state in the same way that the post content is. It is available at {post}.excerpt.rendered.

2. Display the destination CPT listing differently from the standard posts

Currently the destination CPT lists posts in the same way as the normal posts. Since it's a different type of content it would be nice if the listing displayed differently. Bear in mind that this list will always be limited so you don't need the pagination.

HINT — You will need to modify list.js. You could check for the truthiness of the isDestinationsArchive property and return different content, or differently styled content, if it's true.

3. Use a single component for both posts and pages

You will recall that during the tutorial we created separate <Post> and <Page> components in separate post.js and page.js files so that posts and pages can be displayed differently. This was useful for learning purposes, but is not optimal. A single component can handle both cases.

Refactor that part of the project to dispense with the <Page> component, and so that the <Post> component handles both posts and pages.

HINT — The <Post> component should conditionally check the isPost property and display the posted date and author information only if it is true. If it is not true but isPage is true then this additional information should not be displayed.

You will also need to modify the <Switch> in the root component as the <Page> component will no longer exist.

4. Create a destination component to display the custom post type differently

The destination CPT currently uses the <Page> component to render its content. Create a new component that displays destinations differently.

HINT — Remember that you will need to change index.js to load your new component when data.isDestinations is true.

5. Put the <Header> in its own component

The <Header> component is currently part of the main <Root> component in index.js. This makes the index.js file rather long.

Separate the <Header> component into its own file along with the related CSS-in-JS styling.

HINT — Remember that you will need to import the <Header> component into index.js. As the header contains data from the state and action methods you will also need to connect your new component with the connect HOC.

6. Show the featured image

At the moment we're not showing any featured images in our site, so our site lacks some visual interest. Try showing the featured image on the single post page or even on the listing page.

HINT — The post data has a featured_media property. This contains the ID of the featured image for that post. You can then retrieve the data pertaining to the image in state.source.attachment[{id}], including the link and source_url properties.

7. Display the destination listing by region

The destinations CPT has a custom taxonomy called 'regions'. Display the destinations by region using this custom taxonomy. Currently the values available are 'Africa', 'Americas' and 'Europe'.

HINT — You will need to add the configuration for the custom taxonomy to frontity.settings.js - see . You should then update list.js, or at least the part of it that you implemented in 2 above.

Frontity community forum
the documentation here