Module

Archived
Forum
(read-only)


For official support, visit the official support site »

Link Vault

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5

Back to this add-on's main page
View Other Add-ons From Masuga Design

     

Get the top five downloads, but display the entries they’re attached to?

Support Request

Mike Mella
Mike Mella

I have a Downloads channel where I create entries containing these fields:
- Title
- Description
- File

I’m using Link Vault to track downloads of the File field.

I want to display a “Top 5 most downloaded files” section on my homepage, but I don’t want to list the filenames themselves, I want to display field content from the channel entries that they’re uploaded to, like this:

1. <a href="{file-download-link}">{title}</a>
{description}
2. 
<a href="{file-download-link}">{title}</a>
{description}
3. 
<a href="{file-download-link}">{title}</a>
{description}
etc

I guess I need to wrap the :records tag in a Channel Entries tag somehow?

Ben Kohl
# 1
Ben Kohl

Actually, it would be the other way around. You’d loop through the rows with the :records tag then use the entry_id column (as long as it is populated) to fetch the related entry data using a channel entries tag or the query module. I’d probably go with the query module since it is a small number of columns.

New download links could be generated from the data in the Link Vault download record so you wouldn’t even need the entry’s File field data from the entry query.

Mike Mella
# 2
Mike Mella

Something like this?:

Download Link:

{exp:link_vault:download_link 
       file_path
='{cf-file}' 
       
text='{title}'
       
entry_id='{entry_id}'
      

Download Records:

{exp:link_vault:records 
    table
='downloads' 
    
group_by='file_name' 
    
order_by='census' 
    
sort='desc' 
    
limit='5'
  
}
    {exp
:channel:entries channel="documents" dynamic="no" entry_id="{entry_id}"}
      {title} was downloaded {census} times
. <br><br>
    
{/exp:channel:entries}
{
/exp:link_vault:records} 

That doesn’t seem to work. The Entry ID is says “0” for every entry. Am I capturing it wrong?

Ben Kohl
# 3
Ben Kohl

If you check the entry_id column in the link_vault_downloads table, are all the values 0? If so, maybe the {entry_id} variable in the download link tag isn’t parsing correctly. If the :download_link tag is inside a channel entries loop, it should be parsing fine. Maybe another tag is overriding the {entry_id} variable?

Mike Mella
# 4
Mike Mella

Okay I think I resolved that - I’m using Stash and I should have passed in a stashed value for the entry_id. Seems to work now.

But I’d like to have the documents in the records list clickable, so that you can download them right from there. Is it possible to nest a {exp:link_vault:download_link} tag inside the {exp:link_vault:records} tag?

Ben Kohl
# 5
Ben Kohl

Yes. You just might have to experiment with the parse=“inward” parameter depending on how your templates are set up.

Mike Mella
# 6
Mike Mella

Thanks Ben. One more thing - Is there an easy way to clear out the download records? I’m testing the site and don’t want these entries counted when I launch.

Ben Kohl
# 7
Ben Kohl

The easiest way would be a SQL query. If you use Sequel Pro or another GUI, you could just delete the rows from there.

DELETE FROM exp_link_vault_downloads