Add 'active' class to K2 Content Module Item - joomla

I have searched to the end of the internet and cannot find an answer to this and my limited php knowledge is making this seemingly easy task very difficult.
The file is modules/mod_k2_content/templates/default/default.php around LINE 22
Here is the code:
<li id="" class="<?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1) echo ' lastItem'; ?>">
I simply need to add an 'active' to the class area IF the li is the page I am currently viewing in order to highlight it with CSS.

You should be able to check the standard joomla routing variables to do some checks. I don't use K2 much, so you may have to play with the values to get this working in your case:
$jinput = JFactory::getApplication()->input;
$option = $jinput->get('option');
$view = $jinput->get('view');
$id = $jinput->get('id');
I would then compare those values to the items in the link that are likely in the code directly after the code that you have included. If all three match, you are on that page!

David's answer is correct you need to check for option,view and id and than add the class to li here is rest of the code -
<?php
$jinput = JFactory::getApplication()->input;
$option = $jinput->get('option');
$view = $jinput->get('view');
$id = $jinput->getInt('id'); ?>
<?php foreach ($items as $key=>$item):
$liclass = '';
if(($option=='com_k2') && ($view=='item') && ($id==$item->id)){
$liclass = 'active ';
});
?>
<li class="<?php echo $liclass?><?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1) echo ' lastItem'; ?>">
Hope this will help.

Here is the correct code:
<?php $id = JRequest::getVar('id'); ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1) echo ' lastItem'; echo ($id == $item->id)?" active":""; ?>">

Related

Activate default tabs based on condition

I have the following code a page that holds 3 tabs as follow:
<div id="tab-container">
<button class="tablink" onclick="openPage('Wall', this, '#F06078')" id="defaultOpen">Wall</button>
<button class="tablink" onclick="openPage('Profile', this, '#F06078')">Profile</button>
<button class="tablink" onclick="openPage('Gallery', this, '#F06078')">Gallery</button>
The idea is to make whatever tab that's called on from a controller the default and land on it. I try passing $data to the page but it's telling me it's undefined. I also think maybe storing the info in a session and calling it on the page where the tabs are, but I'm not that flexible yet with the coding.
function index ($page='wall') {
$data['defaultOpen'] = 'wall';
$data['images_model'] = $this->images_model->get_images();
$this->load->view($page, $data);
}
I know the codes are not all there right now, but hopefully you get the idea. I will probably need to use an IF statement either in php/js and I was hoping someone might give me some feedback on that. Thanks in advance for all input.
controller :
public function index ($page = 'wall') {
$this->load->helper('url'); // only if you haven't load helper in autoload.
$data['images_model'] = $this->images_model->get_images();
$this->load->view('viewName', $data);
}
view :
<?php $active_tab = end($this->uri->segment_array());?>
<button class="tablink<?php echo ($active_tab == 'wall')? ' active':''; ?>" onclick="openPage('Wall', this, '#F06078')" id="defaultOpen">Wall</button>
<button class="tablink<?php echo ($active_tab == 'profile')? ' active':''; ?>" onclick="openPage('Profile', this, '#F06078')">Profile</button>
<button class="tablink<?php echo ($active_tab == 'gallery')? ' active':''; ?>" onclick="openPage('Gallery', this, '#F06078')">Gallery</button>
The first method is to use parameters in the URL like http://localhost/example.com/home?tab=wall
Then use this URL parameter to active your tab
$tab = $this->input->get('tab'); //wall
<button class="tablink <?php if($tab == 'wall'){ echo 'active';}?>" onclick="openPage('Wall', this, '#F06078')" id="defaultOpen">Wall</button>
Apply same for other tabs as well
The second method is to pas variable to view. Use variable not a parameter in a function
function index() {
$data['defaultOpen'] = 'wall';
$data['images_model'] = $this->images_model->get_images();
$this->load->view($page, $data);
}
Use $defaultOpen like this
<button class="tablink <?php if($defaultOpen == 'wall'){ echo 'active';}?>" onclick="openPage('Wall', this, '#F06078')" id="defaultOpen">Wall</button>
Try something like this
// controller
public function index ($page = 'wall') {
// pass the selected data to view
$data['selectedPage'] = $page;
$data['images_model'] = $this->images_model->get_images();
$this->load->view('viewName', $data);
}
// view
// use ternary operator to set active class to tab
// example:
// <?php echo $selectedPage== 'wall' ? 'active' : '' ?>
// code above means if $selectedPage equals 'wall', set class to active,
// if not do nothing
<button class="tablink <?php echo $selectedPage== 'wall' ? 'active' : '' ?>"
onclick="openPage('Wall', this, '#F06078')"id="defaultOpen">Wall</button>
<button class="tablink <?php echo $selectedPage== 'profile' ? 'active' : '' ?>"
onclick="openPage('Profile', this,
'#F06078')">Profile</button>
<button class="tablink <?php echo $selectedPage== 'gallery' ? 'active' : '' ?>"
onclick="openPage('Gallery', this,
'#F06078')">Gallery</button>

add blog picture to user profile page in joomla contact page

I want to add the article's pictures before the articles titles in the contact (user profile page ) like so:
Also, I have created an ovveride into a template html/com_contact/contact
and I have added this code but it gives a warning:
"Notice: Undefined property: stdClass::$images"
and no image.
Code:
/ Create a shortcut for params.
$images = json_decode($this->item->images);
$introImage = $images->image_intro;
?>
<?php if ($this->params->get('show_articles')) : ?>
<div class="contact-articles">
<ul class="nav nav-tabs nav-stacked">
<?php foreach ($this->item->articles as $article) : ?>
<li>
<?php echo JHtml::_('link',
JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article-
>catid, $article->language)), htmlspecialchars($article->title, ENT_COMPAT,
'UTF-8')); ?>
<?php echo $introImage; ?>
</li>
How can I get this fixed?
i have fixed it by using this cod ;
// Create a shortcut for params.
$article_id = $article->id; // get article id
//aticle_id = JFactory::getApplication()->input->get('id'); // get article
id
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('images'))
->from($db->quoteName('#__content'))
->where('id = '. $db->Quote($article_id));
$db->setQuery($query);
$result = $db->loadResult();
$intro_image = json_decode($result)->image_intro;
//var_dump($intro_image);
//echo $intro_image;
echo "<img src=\"".$intro_image."\" alt=\"icon\" >";

Link to Page if active in store view in Magento

I try to add a link to a cms page if the page active in store view but don't work. If the page is only active for the store A, keeps appears in store B. Magento 1.9.1.1
<?php $active = Mage::getModel('cms/page')->setStoreId($storeId)->load('guia', $storeId)->getIsActive(); ?><?php if ($active == '1') : ?><?php $aCmsPage = Mage::getModel('cms/page')->load('guia', 'identifier'); $theTitle = $aCmsPage->getTitle(); echo $theTitle; ?><?php endif; ?>
Thank you
<?php
$cmsCollections = Mage::getModel('cms/block')->getCollection();
$attribute = "identifier"; //name of column like Identifier, Title etc.
$value = "home-page-static"; // Value of attribute
$cmsCollections->addFieldToFilter($attribute, $value);
$item = $cmsCollections->getFirstItem();
$id = $item->getData('is_active');
if($id == 1){
echo "CMS PAGE or Static Block Exists and Enable";
}else{
echo "CMS PAGE or Static Block is in-active";
}
?>

Google Affiliate Integration with Magento 1.7

So maybe you guys can help me out here, im trying to integrate googles tracking pixel for their Google Affiliate program. Im using the following code from here http://www.studio1909.com/2009/10/16/google-affiliate-network-conversion-tracking-pixel-magento-ecommerce/ However, after going back and forth with google they aren't so excited about the way the code from the above link is printing out the data when it comes to configurable products.
<!--Start Google Affiliate Integration-->
<?php
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$order = Mage::getModel('sales/order')->load($lastOrderId);
foreach ($order->getAllItems() as $item) {
$productArray[] = array(
"product_sku" => $item->getSku(),
"product_magento_id" => $item->getProductId(),
"product_name" => $item->getName(),
"product_qty" => $item->getQtyOrdered(),
"product_price" => $item->getPrice(),
"product_discount_amount" => $item->getDiscountAmount(),
"product_row_price" => $item->getPrice() - $item->getDiscountAmount(),
);
};
?>
<?php
$_totalData = $order->getData();
$_subtotal = $_totalData['subtotal'];
$_orderID = $_totalData['increment_id'];
?>
<img src="https://clickserve.cc-dt.com/link/
order?vid=KVENDORID&oid=<?php echo "$_orderID"; ?>&amt=<?php echo "$_subtotal"?>&prdsku=<?php foreach ($productArray as $key) {echo $key['product_sku']."^";};
?>&prdnm=<?php foreach ($productArray as $key) {echo $key['product_name']."^";};
?>&prdqn=<?php foreach ($productArray as $key) {echo $key['product_qty']."^";};
?>&prdpr=<?php foreach ($productArray as $key) {echo $key['product_price']."^";};
?>&prcatid=<?php foreach ($productArray as $key) {echo "your-product^";};
?>" width=1 height=1>
<!--End Google Affiliate Integration-->
This is the end result
<!--Start Google Affiliate Integration-->
<img src="https://gan.doubleclick.net/gan_conversion?advid=MYID&event_type=transaction&oid=10000XXXX&amt=19.0000&fxsrc=USD&prdsku=DVT2756CH CHAR M^DVT2756CH CHAR M^&prdnm=DaVinci 1952 In Charcoal T-Shirt^DaVinci 1952 In Charcoal T-Shirt^&prdqn=1.0000^1.0000^&prdpr=19.0000^0.0000^&prcatid=4425^4427^" width=1 height=1>
<!--End Google Affiliate Integration-->
So the question is there a way to edit the code above so it just echoes the main configurable product without the simple product.
Thanks!
One good place to look at this is the template for displaying the order items:
app/design/frontend/base/default/template/sales/order/items.phtml
and the code for the loop is:
<?php $_items = $_order->getItemsCollection(); ?>
<?php $_index = 0; ?>
<?php $_count = $_items->count(); ?>
<?php foreach ($_items as $_item): ?>
<?php if ($_item->getParentItem()) continue; ?>
So this can be a good way to get what you need.

Wordpress The Events Plugin wp_query not paginating

I've got an issue with Modern Tribe's "The Events Calendar" plugin not paginating properly. It displays the first page fine, but refuses to go to any secondary pages (using wp-pagenavi). Ideally, I'm trying to have it load via AJAX, but at this point pagination would be a miracle. I've exhausted an entire day here. Basically, this is the query:
<?php
$wp_query = new WP_Query();
$wp_query->query( array(
'post_type'=> 'tribe_events',
'eventDisplay' => 'upcoming',
'posts_per_page' => 5)
);
$max = $wp_query->max_num_pages;
$paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) :
$wp_query->the_post();
?>
<li><!-- do stuff --> </li>
<?php
endwhile;?>
</ul>
<?php
endif;
wp_reset_query(); // important to reset the query
?>
There are quite a number of issues with your loop:
You say you're using wp_page_navi, however I'm not seeing any references to the plugin in any of your code. Also, you have list items being generated in your loop along with a closing ul tag, but I don't see any opening ul tag anywhere, which could also be contributing to some of your problems.
I'm also noticing in your list of arguments that you're trying to set 'eventDisplay' to 'upcoming'. 'eventDisplay' is not a valid WP_Query parameter. I'm guessing you probably have a registered Taxonomy of eventDisplay? If so, you will need to use Tax Query instead. I've removed this parameter in the example, but feel free to replace it when you're comfortable with setting the parameters you need.
Lastly, query arguments should be made when you call WP_Query, not through $query->query.
Here's something I came up with using standard Wordpress Paging and the arguments you have in your code. I'm not familiar with wp_page_navi, but this should help get you started on the right track:
<?php
global $paged;
$curpage = $paged ? $paged : 1;
$query = new WP_Query(array(
'post_type'=> 'tribe_events',
'paged' => $paged,
'posts_per_page' => 5
));
if ($query->have_posts()) :
?>
<ul>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php
echo '<div id="wp_pagination">';
echo '<a class="first page button" href="'.get_pagenum_link(1).'">«</a>';
echo '<a class="previous page button" href="'.get_pagenum_link(($curpage-1 > 0 ? $curpage-1 : 1)).'">‹</a>';
for($i=1;$i<=$query->max_num_pages;$i++)
{
echo '<a class="'.($active = $i == $curpage ? 'active ' : '').'page button" href="'.get_pagenum_link($i).'">'.$i.'</a>';
}
echo '<a class="next page button" href="'.get_pagenum_link(($curpage+1 <= $query->max_num_pages ? $curpage+1 : $query->max_num_pages)).'">›</a>';
echo '<a class="last page button" href="'.get_pagenum_link($query->max_num_pages).'">»</a>';
echo '</div>';
endif;
wp_reset_query();
?>
This will set your loop to display 5 post titles in your list. Below it will be a series of numbered links based on how many posts you have. When you click on a number, it reloads the page with its corresponding titles.
Let me know if this helps.

Resources