Inu
Kode TWIG buat random posting di xtblog....?
TechnoSparks
Inu Graham would not able to understand you. You should use english instead.
Graham, he requested you to show a twig code that changes the behaviour of the blog block to show random posts rather than an arranged list.
Graham
Inu it translates as "TWIG code for a random post on xtblog"
if you wish to show ONE random post instead of the list
in the blog twig block
{% block entries_list %}
remove the line
{% for entry in data.entries %}
and replace it with
{%set entry=data.entries[(random(data.entries|length-1))] %}
Copy code
and remove the corresponding
{% endif %}
you will need to set your blog function to
entries_per_page="0" to use the whole post list
As this is set in the twig ALL blog functions on the site will be affected the same
This is where I have tested it
http://blogtwig.xtgem.com/blag
Inu
Graham thanks graham, and how to set the <meta name = automatically on every post in xtblog ....?
Graham
Inu Which meta tags ? and set to which part of the posts content?
It needs to use xtscript
Inu
Graham yes meta tag .. set to _headertags part .... It may show the code ..
Graham
Inu This is a complete page code
It now takes the contents of the post up to the first </div>
You can still use the blog on the page from the building tool just be careful of the other lines
disable any other description meta tag the new tag is inserted by {_$$meta|}
<!DOCTYPE html>
<html>
<head>
{_$$meta|}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>x</title>
</head>
<body>
<div data-xtcontainer="container" class="xt_container"><xt:code><!--parser:xtscript-->
# </xt:code>
var $blog=<xt:blog tzone="0" format="Y-m-d" display="1" show_time="0" entries_per_page="3" 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>
var $start_post_content = call strpos $haystack=$blog;$needle=xt_blog_content xt_text normal
if $start_post_content >0
var $start_post_content =($start_post_content+32)
var $end_post_content = call strpos $haystack=$blog;$needle=</div>;$offset=$start_post_content
var $post_content = call substr $val=$blog;$start=$start_post_content;$length=($end_post_content-$start_post_content)
var $cleaned_post_content=call strip_tags $val=$post_content
var $meta=<meta name="description" content="$cleaned_post_content" />
endif
print $blog
del $blog
assign $dump=call dump_vars
assign $dump=call trim $val=$dump ; $charlist={{<pre>
Array/ }}
assign $dump=call trim $val=$dump ; $charlist=( )
assign $dump=call htmlspecialchars $val=$dump
assign $dump=call nl2br $val=$dump
print $dump<br/>
<!--/parser:xtscript--></xt:code>
</div>
</body>
</html>
Copy code
Inu
Graham Xtscript you give do not succeed ... Demo
http://streetfilm.sextg em.com/view/
Graham
Inu I have changed the code below
open a post
It now takes the contents of the post up to the first </div>
It then passes it through striptags and uses the result in the description meta tag
This is based on standard twig on a version 2 blog with html enabled in the post
the demo includes a variable dump at thebottom of the page
http://newblogtest.yn.lt/blog