commadno014 Posted June 30, 2015 Share Posted June 30, 2015 I have this code that i created to view posts in different ways (like grid / list and other ) so what i need o do is switch between them to make the users of my site able to choose the way he/she like to view the posts his is my code if {$_CONF['info_row']['style_block_latest_news']} =='1'} <table width="100%" class="border" cellpadding="0" style="border-collapse: collapse"> {Des::while}{LastNews_subjectList} <?php $writer= $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['writer']; $Info_writer = $PowerBB->DB->sql_query("SELECT * FROM " . $PowerBB->table['member'] . " WHERE username = '$writer'"); $InfoWriter = @mysql_fetch_array($Info_writer); $avater_path = $InfoWriter['avater_path']; ?> <tr> <td class="thead"> <?php $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'] = $PowerBB->Powerparse->censor_words($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title']);?> <span class="l-left"> <font class="smallfont"> {$lang['SubjectVisitor']}: ({$LastNews_subjectList['visitor']}) {$lang['Comments']}: ({$LastNews_subjectList['reply_number']}) </font> </span> <span class="r-right"> <img border="0" alt="{$LastNews_subjectList['title']}" src="{$LastNews_subjectList['icon']}"> <a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}">{$LastNews_subjectList['title']}</a> </span> </td> </tr> <tr> <td class="blocks_info"> <span class="l-left"> <font class="smallfont"> {$LastNews_subjectList['write_date']} </font> </span> <span class="r-right"> <img border="0" src="look/portal/images/news_icon.gif" alt="Writer"> {$lang['LastsPostsWriter']} <a href="index.php?page=profile&show=1&id=<?php echo $InfoWriter['id']; ?>">{$LastNews_subjectList['writer']}</a> </span> </td> </tr> <tr> <td class="blocks_info" valign="top"> <span class="l-left UserPhoto"> <?php if ($avater_path){ ?> <a href='<?php echo $avater_path; ?>' rel="facebox"> <img src='<?php echo $avater_path; ?>' alt="Photo" onload="ResizeAv(this)" /> </a> <?php if ($avater_path ==''){ ?> <a href="{$image_path}/ {$_CONF['info_row']['default_avatar']}" rel="facebox"> <img src="{$image_path}/ {$_CONF['info_row']['default_avatar']}" border="0" alt="Photo" onload="ResizeAv(this)" /> </a> {/if} {else} <a href="{$image_path}/ {$_CONF['info_row']['default_avatar']}" rel="facebox"> <img src="{$image_path}/ {$_CONF['info_row']['default_avatar']}" border="0" onload="ResizeAv(this)" /> </a> {/if} </span> <?php $num =$PowerBB->_CONF['template']['_CONF']['info_row']['portal_news_along']; $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = $PowerBB->Powerparse->replace($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = strip_tags($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = str_replace('<br>'," ",$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = str_replace('<br />'," ",$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = $PowerBB->Powerparse->censor_words($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = $PowerBB->functions->words_count($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'],$num); ?> {$LastNews_subjectList['text']} ... <br /> <br /> <br /> <br /> <br /> <br /> <span class="r-right"><a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}"><img border="0" src="look/portal/images/read_more_button.png" alt="readmore"></a></span> </td> </tr> <tr><td class="smbox"><br /><br /></td></tr> {/Des::while} {if {$PagerLastNews}} <tr> <td class="blocks_info"> <br /> <span class="r-right"> {$PagerLastNews} </span> </td> </tr> {/if} </table> {elseif {$_CONF['info_row']['style_block_latest_news']} =='2'} <?php $t= 0;?> <table border="0" width="100%" cellpadding="0" style="border-collapse: collapse" align="center"><tr> {Des::while}{LastNews_subjectList} <?php if ($PowerBB->_CONF['info_row']['portal_columns'] == '1' ) { $columns_News = "3"; } else { $columns_News = "2"; } if($t== $columns_News){ $t=0; echo "</tr><tr>"; }?> <td valign="top"> <table border="1" width="100" class="border" cellpadding="0" style="border-collapse: collapse" align="center"><tr> <td class="LastNews-tabclear" valign="top"> <?php $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'] = $PowerBB->Powerparse->censor_words($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title']); $title = $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title']; $num = "20"; $title = $PowerBB->functions->words_count($title,$num);?> <a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}" title="<?php echo $title;?>"><?php echo $title;?></a> </td> </tr> <tr> <td class="rowthumb" valign="top"> <a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}" title="<?php echo $title;?>"> <?php $x = 1; $images = array(); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = stripslashes($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); preg_match_all('/src=([\'"])?((?(1).*?|\S+))(?(1)\1)/', $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'], $images); foreach ($images[2] as $src) { if($src) { echo '<img border="0" width="200" height="200" src="'.$src.'" alt="'.$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'].'">'; } break; } if(!preg_match_all('/src=([\'"])?((?(1).*?|\S+))(?(1)\1)/', $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'], $images)) { echo '<img border="0" width="200" height="200" src="look/portal/images/traffic_cone.png" alt="'.$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'].'">'; } ?> </a> </td> </tr> <tr> <td class="row1" valign="top"> <?php $num = $PowerBB->_CONF['template']['_CONF']['info_row']['portal_news_along']; $text = $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']; $text = $PowerBB->functions->words_count_replace_strip_tags_html2bb($text,$num); $text = $PowerBB->Powerparse->html2bb($text); ?> <textarea dir="{$_CONF['info_row']['content_dir']}" class="r-right" readonly="readonly"><?php echo $text; ?></textarea> </td> </tr> <tr> <td class="theadv" valign="top"> <a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}" title="Read More"> <div id="read_more_button"> {$lang['SubjectVisitor']}: ({$LastNews_subjectList['visitor']}) {$lang['usercp_reputations']}: ({$LastNews_subjectList['rating']}) </div> </a> </td> </tr> </table> <br /> </td> <?php $t= $t+1;?> {/Des::while} </tr> </table> {if {$PagerLastNews}} <table border="1" width="100%" cellpadding="0" style="border-collapse: collapse"><tr> <tr> <td class="row3"> <span class="r-right"> {$PagerLastNews} </span> </td> </tr> </table> {/if} {elseif {$_CONF['info_row']['style_block_latest_news']} =='3'} <table width="100%" class="border" cellpadding="0" style="border-collapse: collapse"> {Des::while}{LastNews_subjectList} <?php $writer= $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['writer']; $Info_writer = $PowerBB->DB->sql_query("SELECT * FROM " . $PowerBB->table['member'] . " WHERE username = '$writer'"); $InfoWriter = @mysql_fetch_array($Info_writer); $avater_path = $InfoWriter['avater_path']; ?> <tr> <td class="thead"> <?php $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'] = $PowerBB->Powerparse->censor_words($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title']);?> <span class="l-left"> <font class="smallfont"> {$lang['SubjectVisitor']}: ({$LastNews_subjectList['visitor']}) {$lang['Comments']}: ({$LastNews_subjectList['reply_number']}) </font> </span> <span class="r-right"> <img border="0" alt="{$LastNews_subjectList['title']}" src="{$LastNews_subjectList['icon']}"> <a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}">{$LastNews_subjectList['title']}</a> </span> </td> </tr> <tr> <td class="blocks_info"> <span class="l-left"> <font class="smallfont"> {$LastNews_subjectList['write_date']} </font> </span> <span class="r-right"> <img border="0" src="look/portal/images/news_icon.gif" alt="Writer"> {$lang['LastsPostsWriter']} <a href="index.php?page=profile&show=1&id=<?php echo $InfoWriter['id']; ?>">{$LastNews_subjectList['writer']}</a> </span> </td> </tr> <tr> <td class="blocks_info" valign="top"> <span class="l-left rowthumb5"> <a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}" title="<?php echo $title;?>"> <?php $x = 1; $images = array(); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = stripslashes($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); preg_match_all('/src=([\'"])?((?(1).*?|\S+))(?(1)\1)/', $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'], $images); foreach ($images[2] as $src) { if($src) { echo '<img border="0" width="200" height="200" src="'.$src.'" alt="'.$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'].'">'; } break; } if(!preg_match_all('/src=([\'"])?((?(1).*?|\S+))(?(1)\1)/', $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'], $images)) { echo '<img border="0" width="200" height="200" src="look/portal/images/traffic_cone.png" alt="'.$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['title'].'">'; } ?> </a> </span> <div class="text-list"> <?php $num =$PowerBB->_CONF['template']['_CONF']['info_row']['portal_news_along']; $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = $PowerBB->Powerparse->replace($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = strip_tags($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = str_replace('<br>'," ",$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = str_replace('<br />'," ",$PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = $PowerBB->Powerparse->censor_words($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text']); $PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'] = $PowerBB->functions->words_count($PowerBB->_CONF['template']['while']['LastNews_subjectList'][$this->x_loop]['text'],$num); ?> {$LastNews_subjectList['text']} ... </div> <br /> <br /> <br /> <br /> <br /> <br /> <span class="r-right"><a href="index.php?page=topic&show=1&id={$LastNews_subjectList['id']}"><img border="0" src="look/portal/images/read_more_button.png" alt="readmore"></a></span> </td> </tr> <tr><td class="smbox"><br /><br /></td></tr> {/Des::while} {if {$PagerLastNews}} <tr> <td class="blocks_info"> <br /> <span class="r-right"> {$PagerLastNews} </span> </td> </tr> {/if} </table> so hope you under stand what i need and for make i more easy i don't know how to make i is it possible with switch statement in php or it need another language i don't know so hope found the answer here and thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/297121-need-help-to-make-switcher/ Share on other sites More sharing options...
scootstah Posted June 30, 2015 Share Posted June 30, 2015 To do it without a page reload will require Javascript. Otherwise, your PHP logic would basically just check which view was clicked and display the corresponding template. You could differentiate with a querystring variable. Quote Link to comment https://forums.phpfreaks.com/topic/297121-need-help-to-make-switcher/#findComment-1515295 Share on other sites More sharing options...
commadno014 Posted June 30, 2015 Author Share Posted June 30, 2015 so can you do it as Javascript and if you can't give me example of what i can do even if the page have to reload Quote Link to comment https://forums.phpfreaks.com/topic/297121-need-help-to-make-switcher/#findComment-1515296 Share on other sites More sharing options...
scootstah Posted June 30, 2015 Share Posted June 30, 2015 The easiest way with Javascript would be to return both templates with PHP, in a containing element, and then show/hide them on a click event. <div id="grid"> grid template here </div> <div id="list"> list template here </div>But, that's pretty inefficient, since you're doubling the amount of data you're returning to the browser. Another way is to return JSON or something, and format it into your templates with Javascript. If you don't want to use Javascript, your PHP logic is basically as such: $view = 'grid'; if (isset($_GET['view'])) { $view = $_GET['view']; } if ($view == 'grid') { // return grid template } else { // return list template } Quote Link to comment https://forums.phpfreaks.com/topic/297121-need-help-to-make-switcher/#findComment-1515297 Share on other sites More sharing options...
commadno014 Posted June 30, 2015 Author Share Posted June 30, 2015 $view = 'grid'; if (isset($_GET['view'])) { $view = $_GET['view']; } if ($view == 'grid') { // return grid template } else { // return list template } in this area ( // return list template ) should I replace it with the full template code or just this code {$_CONF['info_row']['style_block_latest_news']} =='1'} which i used i in my Admin CP o be able to choose Quote Link to comment https://forums.phpfreaks.com/topic/297121-need-help-to-make-switcher/#findComment-1515301 Share on other sites More sharing options...
scootstah Posted June 30, 2015 Share Posted June 30, 2015 The full template code, for the list view. Quote Link to comment https://forums.phpfreaks.com/topic/297121-need-help-to-make-switcher/#findComment-1515305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.