Is it possible to limit # of entries by custom_field?
Posted: 12 October 2008 12:10 PM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  69
Joined  05-09-2007

I’m looking to create a custom field called “number_of_photos” which will ask for a single number. I would like this number to affect the limit parameter.

For example, if 8 is the value in the number_of_photos field, the weblog would only display 8 entries.

In theory, I would like something similar to this:
{exp:weblog:entries weblog=“photos” limit=”{number_of_photos}”}

Is this possible? Or is there any alternative way to accomplish this?

Thanks for any help.
-Deanna

Profile
 
 
Posted: 13 October 2008 01:11 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  139
Joined  10-04-2007

It should be a doable exercise, but I think you’ll need to either pass the limit parameter [no_of_photos] from another template and simply get it on the template handling display, then use it there. Another option might be to use php to get the variable passed dynamically and simply use it on limit as limit = “<?=$no_of_photo?>”. You might also need to run php on input. If this is not clear, please let me know so I can give example.

Regards,
Marks

Profile
 
 
Posted: 13 October 2008 10:37 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  69
Joined  05-09-2007

Marks,
I would really appreciate an example, thanks for your response.

Profile
 
 
Posted: 13 October 2008 11:57 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  139
Joined  10-04-2007

Hi,

This is what I’d do. I would create a dropdown field as part of my photo weblog fields and then populate it with numbers like 1-20. Alternatively, I’d create a field [text input] where users specify the number of photos they want to see. But it is safe with a dropdown since they will just select a number unlike entering garbage data. Weblog call as follows:
Say the field name is number_of_photos

{exp:weblog:entries weblog=“photos” limit=”{number_of_photos}”}

If by any chance the limit parameter is not regarded as a number since it might be from text field, I’d then use php to convert the value either entered or selected into an interger, because whatever you pass to limit should be an interger, I guess. Conversion like this

<?php
    $no_of_photosStr = “{number_of_photos}”;
    $no_of_photosInt = (int)$no_of_photosStr;
?>

Then weblog call as follows:

{exp:weblog:entries weblog=“photos” limit=”<?=$no_of_photosInt?>”}

You might need to run php on input if nothing happens after this code has been used.

Regards,
Marks

Profile
 
 
Posted: 14 October 2008 10:33 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  69
Joined  05-09-2007

Thank you, Marks! This worked wonderfully and I know it will be used again and again in the future. smile

Profile
 
 
Posted: 16 October 2008 12:02 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  139
Joined  10-04-2007

Hi,

I am happy that it worked out. I tend to feel indebted to EE users in the forums. They are so wonderful and helpful. Good luck.

Regards,
Marks

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64912 Total Logged-in Users: 29
Total Topics: 81864 Total Anonymous Users: 27
Total Replies: 440105 Total Guests: 197
Total Posts: 521969    
Members ( View Memberlist )
Newest Members:  bjmohrAqua193Bios Elementmjpoteetguimogranwelshmrcfthenetmonkeybenekwhobutsb