Using "Favorites"
To create a system of "favorites":
- Render only an upvote button (omitting the downvote button).
- Customize the icon if desired.
- Use functions like
userHistory
andelementHistory
to retrieve the favorites data.
# List all favorited entries
Display a list of the current user's favorited entries...
{% if currentUser %}
<h1>Your Favorite Posts</h1>
{# Get complete user history #}
{% set history = craft.upvote.userHistory(currentUser.id) %}
{# Get IDs of all favorited entries #}
{% set favoriteIds = history | filter(v => v == 1) | keys %}
{# Get entries with matching IDs #}
{% set entries = craft.entries().id(favoriteIds).all() %}
{# Loop over favorited entries #}
{% for entry in entries %}
<div>{{ entry.id }} - {{ entry.title }}</div>
{% endfor %}
{% endif %}