Hi design,
thank you for this idea! I was doing similar thing to incorporate list/grid function in search results instead, not in the main page, but I forgot to copy the small button part php code and couldn't make it work. Now it is working perfectly!
To make it a complete solution here is what has to be done to get grid/list button on the search page results in Modern theme:
in functions.php put this code before the last ?> closing tag:
if(!function_exists('bender_add_body_class_construct')) {
function bender_add_body_class_construct($classes){
$benderBodyClass = benderBodyClass::newInstance();
$classes = array_merge($classes, $benderBodyClass->get());
return $classes;
}
}
if(!function_exists('bender_body_class')) {
function bender_body_class($echo = true){
/**
* Print body classes.
*
* @param string $echo Optional parameter.
* @return print string with all body classes concatenated
*/
osc_add_filter('bender_bodyClass','bender_add_body_class_construct');
$classes = osc_apply_filter('bender_bodyClass', array());
if($echo && count($classes)){
echo 'class="'.implode(' ',$classes).'"';
} else {
return $classes;
}
}
}
if(!function_exists('bender_add_body_class')) {
function bender_add_body_class($class){
/**
* Add new body class to body class array.
*
* @param string $class required parameter.
*/
$benderBodyClass = benderBodyClass::newInstance();
$benderBodyClass->add($class);
}
}
if(!function_exists('bender_nofollow_construct')) {
/**
* Hook for header, meta tags robots nofollos
*/
function bender_nofollow_construct() {
echo '<meta name="robots" content="noindex, nofollow, noarchive" />' . PHP_EOL;
echo '<meta name="googlebot" content="noindex, nofollow, noarchive" />' . PHP_EOL;
}
}
if( !function_exists('bender_follow_construct') ) {
/**
* Hook for header, meta tags robots follow
*/
function bender_follow_construct() {
echo '<meta name="robots" content="index, follow" />' . PHP_EOL;
echo '<meta name="googlebot" content="index, follow" />' . PHP_EOL;
}
}
if( !function_exists('bender_draw_item') ) {
function bender_draw_item($class = false,$admin = false, $premium = false) {
$filename = 'loop-single';
if($premium){
$filename .='-premium';
}
require WebThemes::newInstance()->getCurrentThemePath().$filename.'.php';
}
}
if( !function_exists('bender_show_as') ){
function bender_show_as(){
$p_sShowAs = Params::getParam('sShowAs');
$aValidShowAsValues = array('list', 'gallery');
if (!in_array($p_sShowAs, $aValidShowAsValues)) {
$p_sShowAs = bender_default_show_as();
}
return $p_sShowAs;
}
}
if( !function_exists('bender_default_show_as') ){
function bender_default_show_as(){
return getPreference('defaultShowAs@all','bender_theme');
}
}
/**
CLASSES
*/
class benderBodyClass
{
/**
* Custom Class for add, remove or get body classes.
*
* @param string $instance used for singleton.
* @param array $class.
*/
private static $instance;
private $class;
private function __construct()
{
$this->class = array();
}
public static function newInstance()
{
if ( !self::$instance instanceof self)
{
self::$instance = new self;
}
return self::$instance;
}
public function add($class)
{
$this->class[] = $class;
}
public function get()
{
return $this->class;
}
}
in the beginning of search.php fill-in the empty <?php ... ?> space with this code
<?php
// list-grid selector
bender_add_body_class('search');
$listClass = '';
$buttonClass = '';
if(osc_search_show_as() == 'gallery'){
$listClass = 'listing-grid';
$buttonClass = 'active';
}
?>
in search.php somewhere after <div id="main"> part where it is best to fit in. For example, in my case I have put it after "inner" div
<div id="main">
<div class="ad_list">
<div id="list_head">
<div class="inner">
<!-- Search results list-grid selector -->
<span class="doublebutton <?php echo $buttonClass; ?>">
<a href="<?php echo osc_esc_html(osc_update_search_url(array('sShowAs'=> 'list'))); ?>" class="list-button" data-class-toggle="listing-grid" data-destination="#listing-card-list"><span><?php _e('List', 'bender'); ?></span></a>
<a href="<?php echo osc_esc_html(osc_update_search_url(array('sShowAs'=> 'gallery'))); ?>" class="grid-button" data-class-toggle="listing-grid" data-destination="#listing-card-list"><span><?php _e('Grid', 'bender'); ?></span></a>
</span>
... rest of the code...
in style.css at the end of the file:
/* list-grid button */
.doublebutton {
float:right;
margin-left:10px;
}
.doublebutton a {
border:solid 1px #d1d1d1;
background-color:#f7f7f7;
-webkit-border-radius:2px;
border-radius:2px;
cursor:default;
font-size:11px;
font-weight:bold;
text-align:center;
white-space:nowrap;
height:16px;
outline:0;
padding:5px 6px;
display:block;
float:left;
}
.doublebutton a span {
text-indent:-9999px;
float:left;
width:16px;
height:16px;
background-image:url(images/icons.png);
cursor:pointer;
}
.doublebutton .list-button {
margin-right:-1px;
border-top-right-radius:0px;
border-bottom-right-radius:0px;
border-right:none;
}
.doublebutton .list-button span {
background-position:-16px -16px;
}
.doublebutton .grid-button {
border-top-left-radius:0px;
border-bottom-left-radius:0px;
border-left:none;
}
span.active a.grid-button span {
background-position:-16px 0;
}
span.active a.list-button {
border:solid 1px #D1D1D1;
background-color:#F7F7F7;
}
span.active a.list-button span {
background-position:0 -16px;
}
.active a.grid-button, .doublebutton a.list-button {
/* modify this line to change colors */
background-color: #35c3d9;
border-color: #23a4b8;
}
and finally:
copy icons.png from bender/images folder into modern/images folder
Regards