ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Multiple Random Image/Weblog Display...

June 16, 2009 12:00pm

Subscribe [4]
  • #1 / Jun 16, 2009 12:00pm

    jrattinger

    13 posts

    Hi All,

    I’m not sure of the best way to display a random combination of image/weblogs on my home page. Any help would be greatly appreciated.

    I have a products category that contains the following sub-categories - “product-line1”, “product-line2”, “product-line3” & “product-line4”. Each product line has a number of custom content fields associated with them, including product info and several different size images.

    My home page consists of one main large image of one of the product lines and 2 images below it that have smaller images and product info of 2 of the remaining 3 product lines. What I need to do is that each time someone views the home page is to have a different and random large product line image display and also 2 different product lines display below. It needs to be random such that each time user X views the home page, he sees a different image the first time.

    Make sense?

    Someone had suggested that I somehow track the user IP addresses. I’m not sure if that makes sense or how I would do that either…

    Thanks,
    John

  • #2 / Jun 16, 2009 12:14pm

    bmschaaf

    171 posts

    It needs to be random such that each time user X views the home page, he sees a different image the first time.

    So, they can’t see the same images at all?  Or only for the first load?

    So, if user-1 sees picture-A, when he visits the first time.  The second time user-1 visits he can’t see picture-A first.  Right?

    Hmm.  I think you will need to write a cookie…but with what info…tough to say- but I figured I would ask for clarifications for the sake of others.

  • #3 / Jun 16, 2009 12:18pm

    lebisol

    2234 posts

    You can use order by=“random” parameter and hand pick from whichcategories.

  • #4 / Jun 16, 2009 12:20pm

    bmschaaf

    171 posts

    You can use order by=“random” parameter and hand pick from whichcategories.

    And, of course, handpick multiple weblogs…

    But, if you need to ensure that the images aren’t seen first twice…I have no clue.

  • #5 / Jun 16, 2009 12:41pm

    lebisol

    2234 posts

    “images aren’t seen first twice”
    - well eventually they will be looped and seen again or he will run out of items to show. I guess jrattinger needs to decide on acceptable level or “random” vs. “never repeated random”...but my skills with hand made cookies stop here.

  • #6 / Jun 16, 2009 12:45pm

    jrattinger

    13 posts

    Thanks for the quick response!

    In regards to the images viewed the first time on the page, I just don’t want the user to see the same pictures each time they first come to the home page. If the random function is truly random, then perhaps we’re fine without a cookie.

    I’m not sure exactly how to utilize the random function and access my weblogs, but I will fool around with it and figure it out.

    I just remembered one other detail. There will be serveral large images for each sub-category type. So, there might be 5 large images for sub-category 1, 3 large images for sub-category 2,.... If any one of the 5 images are displayed for sub-category 1, then only images for the remaining sub-categories may be used below.

    Perhaps I need to create a new weblog and assign each image a category.

  • #7 / Jun 28, 2009 7:47pm

    jrattinger

    13 posts

    I’m still having trouble with this one…

    I got half way there, by using the orderby=“random” parameter. The problem is that I now want to track the current sub-category and use it in a list of sub-categories NOT to include in my next image. What I’m trying to do is to store any “used” sub-categories in a PHP variable. I’m having a problem however with my PHP variable. I am setting the variable equal to the current category_id. The problem is that it seems to work fine when I’m in the category pair loop. As soon as I reference the variable “$current_category” outside the category pair, it displays “{category_id}”. I have no idea how to resolve this. Note, that I currently am assinging the variabe as follows - <?php $current_category = ‘{category_id}’; ?>. I have tried with double quotes and no quotes as well.

    I have been banging away for longer than I want to admit. PHP is enabled for output.

    And ideas would be great, thanks.

    See the sample code below…

    
    									
  • #8 / Jul 16, 2009 12:31pm

    jrattinger

    13 posts

    Can someone please help me with this problem? I don’t know if this is a scope problem inside a weblog:entries pair, or a simple PHP error.

    I need to do several weblog queries based on earlier queries on the top of my page.

    Any incite would be great!

  • #9 / Jul 16, 2009 11:07pm

    DRUMZ

    75 posts

    That’s a tough one. When I copied your code just as it is, the category number displayed properly in every spot. Inside category loop, outside category loop, and outside entries loop. Are you POSITIVE you have PHP set to parsing OUTSIDE? Cause when I set it to parsing INSIDE, I get what you get. The correct number only when it’s inside the loop, and the two outside ones show {category_id}.

  • #10 / Jul 16, 2009 11:26pm

    jrattinger

    13 posts

    Hi DRUMZ,

    Thanks for the help. Your right, I had the php stage set to input. When I set it to output it works fine.

    I now have another issue. I am now trying to setup a second weblog query based on the category_id from the first query. I’m sure there is a better way to write this, but in order to keep it simple, I setup a new category search string and then try to use it in my second search. The second search always returns nothing, while if I hard code some values, the search works.

    I assume that there is something wrong with the way that I am using php in the cateory string (category=”<?php echo $second_search; ?>”}). I found this exact usage in a post in the forum, so i don’t know what to do.

    Any suggestions?

    
    
    

    And thanks again!
    John

  • #11 / Jul 17, 2009 12:54pm

    DRUMZ

    75 posts

    Thinking about it, you can avoid your whole middle php “if” statements altogether.

    You already know which category came up the first time because it’s in the $category_id variable. Therefore, when making the second tag, you could use the category=“not” parameter. The “not” part would tell it to not grab anything from that category, and thusly it wont be used again.

    Try removing this part:

    <?php
    if($first_category == "10") {
        $second_search = "11|12";
    }
    elseif($first_category == "11") {
        $second_search = "10|12";
    }else {
        $second_search = "10|11";
    }
    ?>

    And just use this for your second entries tag:

    
    
    

    Since you know the variable $category_id will still be there, the “not” part in the second weblog entries tag will pull categories that aren’t the one that was used the first time.

    Hope if it works for ya.

  • #12 / Jul 17, 2009 4:20pm

    jrattinger

    13 posts

    Drumz,

    Thanks again. adding the “not” to the category makes sense. I will also have to do this again and set the category=not<first & second category id’s>. Shouldn’t be a big deal.

    The weird problem that I’m having is that my php code in the category = part is not working. In this case, I have a php variable $third_search that is definitely set with a value. I have PHP turned on and the staging is set to output. See this output from the debugger.

    (0.094469) Tag: {exp:weblog:entries weblog="marketing" orderby="random" limit="1" category="<?php echo $third_search; ?>"}

    I have no idea why this is behaving this way.

    thanks,
    John

  • #13 / Jul 17, 2009 4:56pm

    DRUMZ

    75 posts

    This one’s being a pest isn’t it? You had said before that your code was over 150 lines before and you couldn’t post it, but can you copy it to a text file and attach the file? It’s hard to fight php without seeing the whole pictures. Sometimes there’s an AHA! moment from a second set of eyes 😊

  • #14 / Jul 17, 2009 6:55pm

    jrattinger

    13 posts

    Hey Drumz, I greatly appreciate your efforts… Being that It’s almost happy hour (at least here on LI), I’d like to send your a virtual beer. Maybe a few if we have that “AHAAA” moment.

    Here’s the file of where I am using the code. It’s in my home/index page. I’m under a tight time schedule, so I have crammed and hacked the code to get a solution, but it’s not really the solution that I wish to keep.

    you can actually see the dev code in action at - http://www.crisloid.com/ee/index.php/crisloid/. I’ve have a number of head bangers on this project. The side nav on my product pages has been especially brutal.

    ARGGGGGH! I can’t upload the file. I’m getting the error - Error Message:  The file you are attempting to upload has invalid content for its MIME type.

    Thanks again,
    John

  • #15 / Jul 20, 2009 2:44pm

    DRUMZ

    75 posts

    <—- Non drinker, heh. I’ll take a coke though 😊

    Anyhoo, it seems to be working the way you want it. I get a different image each time I reload, and the two images on the bottom are different from the top one and each other each time I reload too. Is it still doing something you’re not wanting it to?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases