tiaxgame
xtblog add function random, it's help xtblog SEO good than!
tiaxgame
@graham
I can't 'get' tags of
{% block entries_list %} as blogtwig.xtgem.com
Graham
tiaxgame I have added it like this to the top of {% block entries_list %}
I gave it it's own div and class
{% block entries_list %}
<div class="xt_blog_post_list">
{% for entry in data.entries %}
<div class="xt_item">
{% if entry.tags is not empty %}
<div class="xt_tags">
{% for tag in entry.tags %}
<a href="{{ tag.url }}">{{ tag.name }}</a>
{% if not loop.last %}, {% endif %}
{% endfor %}
</div>
{% endif %}
Copy code
Don't forget to add
include_tags_in_post_list="1" to your blogs xtfunction
tiaxgame
Graham ok, thank!
Else problem random, can it action !?
Graham
tiaxgame I guess that depends on what you want to achieve.
random what ?
random post button?
random order list ?
explain
tiaxgame
Graham i want random post 'auto'
Else random list post
http://tutorlewathp.xtgem.com/
It isn't auto
Graham
tiaxgame This script uses a combination of xtscript and javascript
The xtscript is used to convert the blog post list into a javascript array which is then shuffled and a number of the elements are then used to create the post list.
The code is based on a standard blog without custom twig although it should still work as long as you do not change the standard post list too much.
It requires that the list entries are still in a <div class="xt_item"> and that there are no other <div> elements inside the <div class="xt_item"> so the post list tag code would need to use something like <span class="xt_tag" style="display:block"> instead of a <div>
NOTE: using the list tags in this list will probably break it
There are parts of the script that use urlencoded data so that it displays correctly in the xtgem building tool
the #</xt:code>...#<xt:code> lines are so you can still use the blog function from the building tool
everything else must only be edited in the code editor
How slow it will be with a really big blog with hundreds of posts I do not know
DEMONSTRATION PAGE
http://twig.yn.lt/blogtest
<script type="text/javascript">
function shuffleArray(array) {
for (var i = array.length - 2; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];array[j] = temp;}
return array;}
</script>
<!--parser:xtscript-->
# Note this script will not work in preview
# some data is urlencoded to protect the building tool layout
# The blog function
# NOTE entries_per_page Must be 0
# </xt:code>
var $blog_list=<xt:blog tzone="0" format="Y-m-d" display="5" show_time="1" entries_per_page="0" comments_per_page="20" comments_sort="-1" entries_sort="-1" display_limit="0" display_symbol="" version="2" t_back_to_posts="" t_comments="" t_comments_empty="" t_post_a_comment="" t_name="" t_comment="" t_post="" t_tags="" t_search="" t_created="" t_showing_tagged_posts="" t_no_entries_found="" t_no_search_results_found="" t_show_all_comments="" t_see_parent_thread="" t_show_all_replies="" t_show_replies="" t_reply="" t_posting_as="" t_comments_login_required="" t_login="" t_signup="" t_confirm_email="" t_report_spam="" />
# <xt:code>
# Number of random posts to display in the list
var $posts_to_display=5
# Check for post or post list
get __xtblog_entry
if not $__xtblog_entry
# Convert the post list into a javascript array
# Trim data
var $trim_start=call strpos $haystack=$blog_list;$needle=div class="xt_item"
var $trim_end=call strrpos $haystack=$blog_list;$needle=span
var $blog_list=call substr $val=$blog_list;$start=($trim_start-1);$length=($trim_end-$trim_start+6)
# Remove carriage returns
var $cr=call urldecode $val=%0A
var $blog_list=call str_replace $subject=$blog_list;$search=$cr;$replace
# Remove excess white space
var $ws=call urldecode $val=++
var $blog_list=call str_replace $subject=$blog_list;$search=$ws;$replace
# Separate into array elements
var $close_div=call urldecode $val=%3C%2Fdiv%3E
var $blog_list=call str_replace $subject=$blog_list;$search=$close_div;$replace=$close_div','
var $blog_list='$blog_list$close_div'
# Set up the standard blog post list divs (encoded to protect building tool)
call urldecode $val=%3Cdiv+class%3D%22xt_blog_parent%22+id%3D%22xt_blog%22%3E%3Cdiv+class%3D%22xt_list%22%3E%3Cdiv+class%3D%22xt_blog_post_list%22%3E
# Output the random post list
print <script type="text/javascript">var list=[$blog_list]
print_raw ;var list = shuffleArray(list);for(var i=0;i<
print $posts_to_display
print_raw ;i++){document.write(list[i]);}</script>
# Close the post list divs
print $close_div$close_div$close_div
else
# Fix a bug in the comment form
var $blog_list=call str_replace $subject=$blog_list;$search=name="__xtblog_entry" value="";$replace=name="__xtblog_entry" value="$__xtblog_entry"
# Output the post
print $blog_list
endif
<!--/parser:xtscript-->
Copy code
tiaxgame
Graham If want random in {% block entries_list %} of xtblog.twig, i what to do!?