Custom pagination classes Joomla Virtuemart 2 - php

I need to assign an custom class, lets named it "custom" to the Virtuemart Pagination "Next" link or li. Now every Li from my Ul had class "Next", but what code i should use to make Li with the link to the next page had custom class?
Here is the code
function pagination_item_active(&$item) {
$cls = '';
if ($item->text == JText::_('Next')) { $item->text = '»'; $cls = "next";}
if ($item->text == JText::_('Prev')) { $item->text = '«'; $cls = "previous";}
if ($item->text == JText::_('First')) { $cls = "first";}
if ($item->text == JText::_('Last')) { $cls = "last";}
return "<li class=\"next\"><a class=\"".$cls."\" href=\"".$item->link."\" title=\"".$item->text."\">".$item->text."</a></li>";
}
function pagination_item_inactive(&$item) {
return "<li class=\"pagination-active\"><a>".$item->text."</a></li>";
}

I have found the answer here http://forum.joomla.org/viewtopic.php?t=444384.
Here is the final solution code:
function pagination_list_render($list)
{
$lang =& JFactory::getLanguage();
$html = "<ul class=\"pagination\">";
$html .= '<li class="first">'.$list['start']['data'].'</li>';
$html .= '<li class="prev">'.$list['previous']['data'].'</li>';
foreach( $list['pages'] as $page )
{
$html .= '<li class="num">'.$page['data'].'</li>';
}
$html .= '<li class="next">'.$list['next']['data'].'</li>';
$html .= '<li class="end">'.$list['end']['data'].'</li>';
$html .= "</ul>";
return $html;
}
function pagination_item_active(&$item) {
return "".$item->text."";
}
function pagination_item_inactive(&$item) {
return "<span class=\"inactive\">".$item->text."</span>";
}
I use it to install infinite ajax scroll script, and it works perfectly.

You can set the custom class CSS using:
li.next {
}
See MDN about CSS.

Related

Mega dropdown menu css for mysql database data

I want to make mega dropdown menu that comes from mysql database. Below is my php code. The code is working well. But the problem is I am unable to make mega dropdown menu for the code below.
I need the mega menu like the example here : https://bootsnipp.com/snippets/featured/bootstrap-mega-menu
My problem is how will I make more div with the below php code .
Plz help me the css for the mega drop down menu as shown above.
<?php
$sql = "SELECT id, product, parent_id, category_link FROM category ORDER BY parent_id, id";
$results = mysqli_query($conn,$sql) or die(mysqli_error()) ;
if($results)
{
while($result = mysqli_fetch_array($results))
{
$category['categories'][$result['id']] = $result;
$category['parent_cats'][$result['parent_id']][] = $result['id'];
}
}
function getCategories($parent, $category)
{
$html = "";
if (isset($category['parent_cats'][$parent]))
{
$html .= "<div id='wrapper'>";
$html .= "<ul class='mega-menu'>\n";
foreach ($category['parent_cats'][$parent] as $cat_id)
{
if (!isset($category['parent_cats'][$cat_id]))
{
$html .= "<li class='mega-menu-drop'>\n <a class='mega-menu-content' href='" . $category['categories'][$cat_id]['category_link'] . "'>" . $category['categories'][$cat_id]['product'] . "</a>\n</li> \n";
}
if (isset($category['parent_cats'][$cat_id]))
{
$html .= "<li class='mega-menu-drop'>\n <a class='mega-menu-content' href='" . $category['categories'][$cat_id]['category_link'] . "'>" . $category['categories'][$cat_id]['product'] . "</a> \n";
$html .= getCategories($cat_id, $category);
$html .= "</li> \n";
}
}
$html .= "</ul> \n";
$html .= "</div>";
}
return $html;
}
?>
<?php echo $data['category'] = getCategories(0, $category);?>
as of your comment. i guess you need some CSS.
this will work on mouse hover. but not on click like in your example:
.mega-menu-drop {
display:none
}
.mega-menu:hover .mega-menu-drop {
display:block
}

Make a Dynamic Drop Down Navigation system

I am trying to create a Dropdown Menu on my site, Ive hit a brick wall and cannot think on how to do it.
Basically i need to check 2-3 variables in a database and out put the correct data.
I have at the moment it checking if its an External Link or Not, and if it contains a submenu, but i can't get it to output the correct information.
Basically i want it to check if its a External or Non-External link, and if it has a submenu, if it has a submenu, to display the menu options underneath it. So say i have menu 1, 2 ,3, 4 and 2,4 has a submenu, i need them to list the other links under them. i have put in my database toplink_id (to represent which link this item should be under) sc_order (which will control the order the sublinks display in) also dropdown (which tells me if the menu has a submenu or not.)
Here is the start of my code
$sql = "SELECT label, url, ext, dropdown FROM content_pages WHERE top_nav='1' AND active='1' ORDER by page_order ASC";
$query = mysqli_query($dbc, $sql) or die (mysqli_error($dbc));
$menuDisplay .= '<div class="bg-2"><div class="container_12"><article class="grid_12"><nav><ul class="menu sf-js-enabled">';
while ($row = mysqli_fetch_array($query)) {
$url = $row["url"];
$nav_label = $row["label"];
$drop_down ='<ul><li>' . $nav_label . '</li></ul>';
if ($row["ext"] == 0 && $row["dropdown"] == 1){
$menuDisplay .= '<li>' . $nav_label . '' . $drop_down . '</li>';
}
elseif ($row["ext"] == 1 && $row["dropdown"] == 1){
$menuDisplay .= '<li>' . $nav_label . '' . $drop_down . '</li>';
}
elseif ($row["ext"] == 0){
$menuDisplay .= '<li>' . $nav_label . '</li>';
}
elseif ($row["ext"] == 1)
{
$menuDisplay .= '<li>' . $nav_label . '</li>';
}
}
$menuDisplay .= '</ul></nav></article></div></div></header>';
mysqli_free_result($query);
Best way I found to do this without using jQuery is use multidimensional Arrays.
// Create a multidimensional array to conatin a list of items and parents
$menu = array(
'items' => array(),
'parents' => array(),
);
// Builds the array lists with data from the menu table
while ($items = mysqli_fetch_assoc($query))
{
// Creates entry into items array with current menu item id ie. $menu['items'][1]
$menu['items'][$items['id']] = $items;
// Creates entry into parents array. Parents array contains a list of all items with children
$menu['parents'][$items['parent']][] = $items['id'];
}
// Menu builder function, parentId 0 is the root
function buildMenu($parent, $menu)
{
$html = "\n";
if ( isset($menu['parents'][$parent]) )
{
$html .= "";
foreach ($menu['parents'][$parent] as $itemId)
{
if(!isset($menu['parents'][$itemId]) && $menu['items'][$itemId]['ext'] == 0)
{
$html .= "<li>\n <a href='../pages/".$menu['items'][$itemId]['link']."'>".$menu['items'][$itemId]['label']."</a>\n</li> \n";
}
else
if(!isset($menu['parents'][$itemId]) && $menu['items'][$itemId]['ext'] == 1)
{
$html .= "<li>\n <a href='../".$menu['items'][$itemId]['link']."'>".$menu['items'][$itemId]['label']."</a>\n</li> \n";
}
if(isset($menu['parents'][$itemId]))
{
$html .= "<li>\n <a href='../pages/".$menu['items'][$itemId]['link']."'>".$menu['items'][$itemId]['label']."<span class='arrow-down'></span></a> \n";
$html .= "<ul style='border-radius: 0px 0px 6px 6px'> \n";
$html .= buildMenu($itemId, $menu);
$html .= "</ul> \n";
$html .= "</li> \n";
}
}
$html .= "\n";
}
$html .= "";
return $html;
}

Item not getting selected through javascript file

I have simple jquery file which slide news, but now some problem has occurred and it's not selecting element. while debugging it shos null value in triggers.
Code for Php file
<?php
/**
* copyright (C) 2008 GWE Systems Ltd - All rights reserved
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
/**
* HTML View class for the module frontend
*
* #static
*/
include_once(JPATH_SITE."/modules/mod_jevents_latest/tmpl/default/latest.php");
class GeraintModLatestView extends DefaultModLatestView
{
function displayLatestEvents(){
$document = JFactory::getDocument();
$this->getLatestEventsData();
$content = "";
$var=count($this->eventsByRelDay);
$testVar=1;
if(isset($this->eventsByRelDay) && count($this->eventsByRelDay)){
$content .='<html>';
$content.='<body>';
$urls= "http://localhost/Mineral/modules/mod_jevents_latest/tmpl/myjs/jquery.min.js";
$content.='<script src="'.$urls.'"></script>';
$urls= "http://localhost/Mineral/modules/mod_jevents_latest/tmpl/myjs/slideshow.js";
$content.='<script src="'.$urls.'"></script>';
$content.='<script> jQuery.noConflict(true);</script>';
$content.='<div style="height:200px; width=300px; overflow: hidden; position:relative; top:0; border:5px double #206BA4; border-radius:7px; text-align:center; ">';
$content .= '<ul class="triggers" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
// Now to display these events, we just start at the smallest index of the $this->eventsByRelDay array
// and work our way up.
$firstTime=true;
$lastElem=false;
// initialize name of com_jevents module and task defined to view
// event detail. Note that these could change in future com_event
// component revisions!! Note that the '$this->itemId' can be left out in
// the link parameters for event details below since the event.php
// component handler will fetch its own id from the db menu table
// anyways as far as I understand it.
$task_events = 'icalrepeat.detail';
$this->processFormatString();
foreach($this->eventsByRelDay as $relDay => $daysEvents){
reset($last);
reset($daysEvents);
// get all of the events for this day
foreach($daysEvents as $dayEvent){
if($testVar==$var)
$lastTime=true;
if(($dayEvent->bgcolor()=='#FF0000')&&($lastTime))
$dst = "text-decoration:blink;border-color:".$dayEvent->bgcolor();
else
$dst = "border-color:".$dayEvent->bgcolor();
if($firstTime) $content .= '<li style="'.$dst.'">';
else $content .= '<li style="'.$dst.'">';
// generate output according custom string
foreach($this->splitCustomFormat as $condtoken) {
if (isset($condtoken['cond'])) {
if ( $condtoken['cond'] == 'a' && !$dayEvent->alldayevent()) continue;
else if ( $condtoken['cond'] == '!a' && $dayEvent->alldayevent()) continue;
else if ( $condtoken['cond'] == 'e' && !($dayEvent->noendtime() || $dayEvent->alldayevent())) continue;
else if ( $condtoken['cond'] == '!e' && ($dayEvent->noendtime() || $dayEvent->alldayevent())) continue;
else if ( $condtoken['cond'] == '!m' && $dayEvent->getUnixStartDate()!=$dayEvent->getUnixEndDate() ) continue;
else if ( $condtoken['cond'] == 'm' && $dayEvent->getUnixStartDate()==$dayEvent->getUnixEndDate() ) continue;
}
foreach($condtoken['data'] as $token) {
unset($match);
unset($dateParm);
$dateParm="";
$match='';
if (is_array($token)) {
$match = $token['keyword'];
$dateParm = isset($token['dateParm']) ? trim($token['dateParm']) : "";
}
else if (strpos($token,'${')!==false){
$match = $token;
}
else {
$content .= $token;
continue;
}
$this->processMatch($content, $match, $dayEvent, $dateParm,$relDay);
} // end of foreach
} // end of foreach
$content .= "</li>\n";
$firstTime=false;
$testVar++;
} // end of foreach
} // end of foreach
//$content=var_dump($var);
$content .="</ul>";
$content .="</div>";
$content .="</body>";
$content .="</html>";
} else {
$content.='<div style="height:200px; width=300px; overflow: hidden; position:relative; top:0; border:5px double #206BA4; border-radius:7px; text-align:center; ">';
$content .= '<ul class="mod_events_latest_table" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
$content .= '<li class="mod_events_latest_first" >'. JText::_('JEV_NO_EVENTS') . '</li>' . "\n";
$content .="</ul>\n";
$content.='</div>';
}
$callink_HTML = '<div class="mod_events_latest_callink">'
.$this->getCalendarLink()
. '</div>';
if ($this->linkToCal == 1) $content = $callink_HTML . $content;
if ($this->linkToCal == 2) $content .= $callink_HTML;
if ($this->displayRSS){
$rssimg = JURI::root() . "media/system/images/livemarks.png";
$callink_HTML = '<div class="mod_events_latest_rsslink">'
.'<a href="'.$this->rsslink.'" title="'.JText::_("RSS_FEED").'" target="_blank">'
.'<img src="'.$rssimg.'" alt="'.JText::_("RSS_FEED").'" />'
.JText::_("SUBSCRIBE_TO_RSS_FEED")
. '</a>'
. '</div>';
$content .= $callink_HTML;
}
return $content;
} // end of function
} // end of class
Jquery file
$(window).load(function ()
{
jQuery.noConflict();
var triggers = $('ul.triggers li');
var lastElem = triggers.length-1;
var target;
triggers.first().addClass('selected');
triggers.hide().first().show();
function sliderResponse(target)
{
triggers.removeClass('selected').
fadeOut(9000).eq(target).addClass('selected').fadeIn(9000);
}
function sliderTiming()
{
if(triggers.length==1)
{
triggers.first().show();
clearInterval(timingRun);
}
else
{
target = $('ul.triggers li.selected').index();
if ( target === lastElem )
{ target = 0; }
else
{ target = target+1; }
sliderResponse(target);
}
}
var timingRun = setInterval(function() { sliderTiming(); },9000);
function resetTiming()
{
clearInterval(timingRun);
timingRun = setInterval(function() { sliderTiming(); },9000);
}
});
The same file working correctly in other joomla template. and i think their must not be problem of any conflict as i have checked it by disabling other model.

Displaying HTML based on the selection

I'm doing this PHP tutorial on OOP and I'm trying to incorporate the procedural code from the essential training into it, to see if I actually learned anything beyond the basics, and I got stuck, big time.
So, I have these two functions inside the class I named Blog:
public function navigation($selected_subject, $selected_page) {
$output = "<ul class=\"subjects\" id=\"accordion\">";
$subject_set = $this->get_all_subjects($public);
while ($subject = mysqli_fetch_array($subject_set)) {
$output .= "<li";
if ($subject["id"] == $selected_subject['id']) { $output .= " class=\"blogselected\""; }
$output .= ">{$subject["menu_name"]}</li>";
$page_set = $this->get_pages_for_subject($subject["id"], $public);
$output .= "<ul class=\"pages\">";
while ($page = mysqli_fetch_array($page_set)) {
$output .= "<li";
if ($page['id'] == $selected_page['id'] ) { $output .= " class=\"blogselected\""; }
$output .= "><a href=\"../public/blog_index.php?page=" . urlencode($page["id"]) .
"\">{$page["menu_name"]}</a></li>";
}
$output .= "</ul>";
}
$output .= "</ul>";
return $output;
}
public function blog_page($selected_page){
if ($selected_page) {
echo "<h2>" . $selected_page['menu_name'] . "</h2>";
echo "<div class=\"page-content\">";
echo $selected_page['content'];
echo "</div>";
} else {
echo "<h2>Welcome to Widget Corp</h2>";
}
}
and this piece of code on the index page:
<?php
$blog = new Blog;
global $selected_page;
global $selected_subject;
?>
<div class="blog">
<div class="blogpost">
<?php echo $blog->blog_page($selected_page); ?>
</div>
<div class="blognav">
<?php echo $blog->navigation($selected_subject, $selected_page); ?>
</div>
</div>
The code partially works. The navigation with subjects and sub-pages gets displayed fine, when the links are clicked the id "?page=1" is passed to the url, but the problem is that the code is not adding a class "blogselected" to the active links, and it also does not display the content when the links are clicked. The only thing that gets displayed in the content area is the h2 "Welcome to Widget Corp" from else condition in the second function, so I believe the variables $selected_subject and $selected_page might be causing the problem, but I just can't figure it out on my own. I spent countless hours trying to solve this and I'm on the brink of giving up completely. What exactly am I missing here?

How to make a tree view from MySQL and PHP and jquery

i need to show a treeview of my categories , saved in my mysql database .
Database table :
table : cats :
columns: id,name,parent
problem is in php part :
//function to build tree menu from db table test1
function tree_set($index)
{
global $menu;
$q=mysql_query("select * from cats where parent='$index'");
if(!mysql_num_rows($q))
return;
$menu .= '<ul>'."\n";
while($arr=mysql_fetch_assoc($q))
{
$menu .= '<li>';
$menu .= '<span class="file">'.$arr['name'].'</span>';//you can add another output there
$menu .=tree_set("".$arr['id']."");
$menu .= '</li>'."\n";
}
$menu.= '</ul>'."\n";
return $menu;
}
//variable $menu must be defined before the function call
$menu = '
<link rel="stylesheet" href="modules/Topics/includes/jquery.treeview.css" />
<script src="modules/Topics/includes/lib/jquery.cookie.js" type="text/javascript"></script>
<script src="modules/Topics/includes/jquery.treeview.js" type="text/javascript"></script>
<script type="text/javascript" src="modules/Topics/includes/demo/demo.js"></script>
<ul id="browser" class="filetree">'."\n";
$menu .= tree_set(0);
$menu .= '</ul>';
echo $menu;
i even asked in this forum :
http://forums.tizag.com/showthread.php?p=60649
problem is in php part of my codes that i mentioned . i cant show sub menus , i mean , really i dont know how to show sub menus
is there any chance of a pro php coder helping me here ?
It looks like you are sending duplicate data to your menu variable, which doesn't need to be there.
I would change your function to do this:
function tree_set($index)
{
//global $menu; Remove this.
$q=mysql_query("select * from cats where parent='$index'");
if(mysql_num_rows($q) === 0)
{
return;
}
// User $tree instead of the $menu global as this way there shouldn't be any data duplication
$tree = $index > 0 ? '<ul>' : ''; // If we are on index 0 then we don't need the enclosing ul
while($arr=mysql_fetch_assoc($q))
{
$subFileCount=mysql_query("select * from cats where parent='{$arr['id']}'");
if(mysql_num_rows($subFileCount) > 0)
{
$class = 'folder';
}
else
{
$class = 'file';
}
$tree .= '<li>';
$tree .= '<span class="'.$class.'">'.$arr['name'].'</span>';
$tree .=tree_set("".$arr['id']."");
$tree .= '</li>'."\n";
}
$tree .= $index > 0 ? '</ul>' : ''; // If we are on index 0 then we don't need the enclosing ul
return $tree;
}
//variable $menu must be defined before the function call
$menu = '....<ul id="browser" class="filetree">'."\n";
$menu .= tree_set(0);
$menu .= '</ul>';
echo $menu;
updated based on comments on question

Categories