Seite 1 von 1
Sycnonising random() order Listviews (resolved)
Verfasst: Sa 21. Mai 2011, 21:30
von Michael_S
Is there a way of sycnonising two listviews on the same page when using a random() order? The first listview is a JQueryTools slider and the second listview is the sliders navigation.
I assume I can do this with objects but would like to use documents
Thanks in advance,
Michael.
Re: Sycnonising random() order Listviews
Verfasst: Sa 21. Mai 2011, 22:12
von Creutzburg
You could do this by storing the output of the random listview in a PHP array. Doing this, you can echo your randomized listview as often as you want.
Let me know if you need further assistance.
Regards,
Alex
Re: Sycnonising random() order Listviews
Verfasst: Sa 21. Mai 2011, 22:39
von Michael_S
Hi Alex,
That makes sense, I've had a look through the forum but can't find a reference could you help me with a code example. Also would this work with both listview type document and object?
Thanks,
Michael.
Re: Sycnonising random() order Listviews
Verfasst: Sa 21. Mai 2011, 23:01
von Creutzburg
Hi Michael,
it doesn't matter if you use it for a document or object listview.
Try this for storing your listview in an array:
Code: Alles auswählen
<?php
$myCounter = 0;
?>
<we:listview name="xyz" type="document" order="random()">
<we:repeat>
<?php
$myArray[$myCounter]["title"] = $lv->f("title"); // let's say you have a field "title" in your listview documents
$myArray[$myCounter]["content"] = $lv->f("content"); // let's say you have a field "title" in your listview documents
$myCounter++;
?>
</we:repeat>
</we:listview>
Now you can echo your listview as you like:
Code: Alles auswählen
<?php
foreach ($myArray AS $key => $value) {
echo $value["title"]; // echoes the title field
}
foreach ($myArray AS $key => $value) {
echo $value["content"]; // echoes the content field
}
?>
I hope that works for you? You could change the listview type to "object" without any changes. The field names "content" and "title" are examples only.
Regards,
Alex
Re: Sycnonising random() order Listviews
Verfasst: So 22. Mai 2011, 00:18
von Michael_S
Hi Alex,
Thanks that was excelent. For anyone else looking at JQueryTools Scrollable (
http://flowplayer.org/tools/index.html) here's the basic working code based on Alex's method to output an Object listview as a scroller with navigation. Alex indicated the same method could be used with a document based listview.
My requirement was to have featured (sticky) posts included in the scroller, for this example the sticky posts are tagged using a checkbox.
1. Include JQuery Tools
Code: Alles auswählen
<script src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>
2. Zero the counter
3. Set your Listview condition (Blog_Featured = checkbox)
Code: Alles auswählen
<we:condition name="featured">
<we:conditionAdd field="Blog_Featured" value="1" compare="=" />
</we:condition>
4. Instigate the listview and count the results
Code: Alles auswählen
<we:listview type="object" name="Featured" order="random()" condition="\$featured" classid="2">
<we:repeat>
<?php
$myArray[$myCounter]["WE_ID"] = $lv->f("WE_ID");
$myArray[$myCounter]["Blog_Title"] = $lv->f("Blog_Title");
$myCounter++;
?>
</we:repeat>
</we:listview>
5. Output the Listview array for the scroll panels
Code: Alles auswählen
<div id="scroll">
<div id="tools">
<?php
foreach ($myArray AS $key => $value) {
echo '<div class="tool" style="background: blue;">';
echo '<div class="content">';
echo '<span class="title">#' . $value["WE_ID"] . ' ' . $value["Blog_Title"] . '</span>';
echo '</div>';
echo '</div>';
}
?>
</div>
</div>
6. Output the scroll navigation in the same order as the panels
Code: Alles auswählen
<div class="navi">
<?php
foreach ($myArray AS $key => $value) {
echo '<a class="slider_nav">#' . $value["WE_ID"] . ' - ' . $value["Blog_Title"] . '</a>';
}
?>
</div>