Random Blog Title Picture

rated by 0 users
This post has 2 Replies | 1 Follower

Not Ranked
Posts 34
Points 445
winterminute Posted: Fri, Mar 28 2008 7:57 PM

I'd like to write some custom code to show a random banner picture when a user views my blog.  Looking at my current theme (paperclip), I see that all of my photos would have to have the paperclip and the little post-it note and of course be the right size/ratio.  Assuming, I could find a way to replicate the paperclip/post-it and made sure all my photos were the right size, it should work.  Ideally, this would be done with some CSS, but given that the current themes have the post-it/paperclip as part of the picture I'm fine with doing that as well.  Should be really easy to create a photoshop template that has this pre-configured and I'll I would need to do is add my photo and export to JPG.

The question is: Where do I make the changes?  I was thinking I'd just store the file names in a separate table in SQL, upload all the photos I'd want to use to my webhost.  Then write some custom code to select a row at random every time the page was loaded substitute that string for the file to load.

The SQL code is easy to write, but what's the correct way and correct place to put this kind of custom code.  My guess is CS has some extensibility that I could just plug into.  Is there a clean easy way to do this, or do I just need to find the right place in the page lifecycle (i.e. Page_Load()) to add some extra code.


  • | Post Points: 20
Top 10 Contributor
Posts 4,039
Points 61,285
TelligentSupportTeam

I think you're thinking along the right lines but I think you could get away without having to make a database call.

If you were to call your pictures along the lines of logo0.jpg, logo1.jpg, logo2.jpg ... logoN.jpg, you could simply get the image path by adding an <asp:image /> control with an id (in this example, imagecontrol) on your page, and then add something like the folowing to Blog.master's Page_Load event

        Random random = new Random();
        imagecontrol.ImageUrl = "somepathtopictures/logo" + random.Next(0, n).ToString() + ".jpg";

where n is an integer representing the highest logo number you have.

  • | Post Points: 20
Not Ranked
Posts 34
Points 445

Duh!  That's a much better way to do it.  Thanks for the info as to where to put the code.


  • | Post Points: 5
Page 1 of 1 (3 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com