Show div depending on class on link - php

I am looping through some images of houses where all have a link to the house detail page. But i have one image that is in the that has a different link where it is being linked to the staff page.
Issue
How do i get that one link to go to the Staff detail page. I have tried to show different blocks of code depending on what class is inserted from the CMS? any suggestions?
<?php
$page_link = team;
if ( $page_link == {#page} ) {
?>
<a href="/team" class="{#remove_link} {#page}" >
<div class="project {#grey_scale} grid-item {#tile_size_width} {#tile_size_height}" style="background:url('{#image_1}{#video_image}');background-size: cover; background-position:center;">
</div>
</a>
<?php
} else {
?>
<a href="{#guid}" class="{#remove_link} {#page}" >
<div class="project {#grey_scale} grid-item {#tile_size_width} {#tile_size_height}" style="background:url('{#image_1}{#video_image}');background-size: cover; background-position:center;">
</div>
</a>
<?php
}
?>

First of all, you dont need to duplicate the whole HTML. You could just set the if around the <a> like:
<?php
$page_link = "team";
if ( $page_link == {#page} ) {
?>
<a href="/team" class="{#remove_link} {#page}" >
<?php } else { ?>
<a href="{#guid}" class="{#remove_link} {#page}" >
<?php } ?>
You need to know what is on {#page}. If it's "team", then you can do your if thing. If not, you have to adjust your $page_link to the same of your {#page} var.
If your team-page adress is something like stansmith.com/pages/team, then you have to change the <a href="/team"> to <a href="/pages/team">.
Please tell me if you need more help.

Related

php - open href like page to specific position

I'd like to know if it's possible to open a page (id=26) at a specific position: .
At the front page i'm using this code at the php file to make the title link to the page
<a href="<?php echo get_page_link(26); ?>">
<?php if(!empty( $clean_biz_home_service_title ) ){ ?>
<h2>
<?php echo esc_html( $clean_biz_home_service_title); ?>
</h2>
</a>
Yes, you can use DOM selectors such as #maincontent. You would need to assign an ID to a section on the page and then append it to the trigger URL.
For ex: http://yourdomain.com/index.html#maincontent would take you to that div on the page.
First, in the content of that page (id=26), you need to add an id attribute to some tag, like so:
<div id="myposition">
...
</div>
Next, append #myposition after the get_page_link(26) call:
<a href="<?php echo get_page_link(26); ?>#myposition">
<?php if(!empty( $clean_biz_home_service_title ) ){ ?>
<h2>
<?php echo esc_html( $clean_biz_home_service_title); ?>
</h2>
</a>
And you are done.
<div name="position">
content
</div>
link
example:
if you click the link below you will open this page at #new-answer position
link

Hide a <li tab if a condition is met [duplicate]

This question already has answers here:
Hiding a Div using php
(6 answers)
Closed 1 year ago.
I have a foreach look that checks if user has a picture or not. If the user doesn't have the picture I want to hide a <li> tab that shows the picture.
Inside my else how do I say, for this user hide tab 2?
I tried using echo 'id="tabHeader_2" style:"visibility:hidden"; but that doesn't work. I need a reference to that tab2, don't I?
<div id="picture<?php echo $i ?>" style="display: none;">
<?php
$picture = $user->pic;
if(isset($picture))
{
// show picture.
}
else
{
// hide tab2
}
?>
</div>
Then the list of tabs:
<div class="profiles">
<div id="tabContainer">
<div class="tabs">
<ul>
<li id="tabHeader_1"> Profile </li>
<li id="tabHeader_2"> Picture </li>
</ul>
</div>
<div id="tabsContent">
<div class="tabpage" id="tabpage_1"></div>
<div class="tabpage" id="tabpage_2"></div>
</div>
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/tabs.js"></script>
</div>
</div>
Picture of what the page looks like:
I am not 100% sure about your code, but you are using isset() which would not be correct, because you set the variable right behind that check so it will be set 100% of the time. You will want to check empty() or is_file() perhaps, depends on what is in that variable.
<!-- This display: none seems strange if you are going to show the wrapped elements -->
<div id="picture<?php echo $i ?>" style="display: none;">
<?php
$picture = $user->pic;
if(!empty($picture)) {
// show picture.
}
else {
// hide tab2
}
?>
</div>
If you put the real code, it would be easier to see how you are laying out your elements.
Do Like This :-
<div class="tabs">
<ul>
<?php
$i = 1;
foreach($yourarray as $key => $value){
if(isset($value) && $value != '')
?>
<li id="tabProfileHeader<?php echo $i;?>"> Profile </li>
<li id="tabPictureHeader<?php echo $i;?>"> Picture </li>
<?php
$i++;
}
?>
</ul>
</div>

Refreshing div with ajax loses link to javascript file

I have a div that includes shoutbox posts. I'm using jQuery and ajax to change the pages within the div. However, when the page changes, it loses the link to the javascript file so that the next time I try to change the page it actually continues with the link action instead of doing the ajax in the background. Then after that it's back to normal and it alternates back and forth between being linked to the file and not.
Also before, it was rendering the whole page so that my layout was being displayed on the refresh instead of just the shoutbox posts. I'm guessing that finally getting it to refresh without re displaying the whole layout again is what's causing it to lose the connection to the javascript file.
This is the code for the posts. The shoutbox_arrows contains the links to change the page. refresh_me is what I'm loading into my div to refresh the content.
<div id="shoutbox_arrows">
<?php $current_page=s tr_replace( '?', '#', getURI(fullURL())); ?>
<ul class="no_dots">
<li id="first_page"><<
</li>
<li id="previous_page"><
</li>
<li><strong>Pg#<?php if ($page > $last_page) {echo $last_page;} else {echo $_SESSION['shoutbox_page'];} ?></strong>
</li>
<li id="next_page">>
</li>
<li id="last_page">>>
</li>
</ul>
</div>
<div id="shoutbox" class="custom_scrollbar">
<div id="refresh_me">
<?php if (sizeof($shouts)==0 ) { ?>
<p>There are no posts.</p>
<?php } foreach ($shouts as $shout) { foreach ($shout as $k=>$v) { $shout[$k] = utf8_encode($v); if ($k == 'guest') { $shout[$k] = ucwords($v); } } ?>
<div class="post_info">
<div class="left">
<?php if ($shout[ 'user_id']==n ull) {echo $shout[ 'guest'];} else { ?><?php echo ucwords(userinfo($shout['user_id'])->username); ?>
<?php } ?>
</div>
<div class="right">
<?php time_format($shout[ 'created_at']); ?>
</div>
</div>
<p class="post_comment" id="shoutbox_comment_<?php echo $shout['id']; ?>">
<?php echo $shout[ 'comment']; ?>
</p>
<?php if (!$shout[ 'last_edited_by']==n ull) { ?>
<p class="last_edited">Edited by
<?php echo ucwords(userinfo($shout[ 'last_edited_by'])->username); ?>
<?php time_prefix($shout[ 'updated_at']); ?>
<?php time_format($shout[ 'updated_at']); ?>.</p>
<?php } ?>
<?php if (current_user()) { if (current_user()->user_id == $shout['user_id'] or current_user()->is_mod) { ?>
<p class="post_edit"> <span class="edit" id="<?php echo $page; ?>">
<a id="<?php echo $shout['id']; ?>" href="<?php $post_to = '?id=' . $shout['id']. '&uid=' . $shout['user_id']; echo $post_to; ?>">
edit
</a>
</span> | <span class="delete" id="<?php echo $page; ?>">
<a href="<?php $post_to = '?id=' . $shout['id']. '&uid=' . $shout['user_id']; echo $post_to; ?>">
delete
</a>
</span>
<span class="hide" id="<?php echo $page; ?>">
<?php if (current_user()->is_mod) { ?> | <a href="<?php $post_to = '?id=' . $shout['id']. '&uid=' . $shout['user_id']; echo $post_to; ?>">
hide
</a><?php } ?>
</span>
</p>
<?php }} ?>
<?php } ?>
</div>
</div>
This is the page that my ajax request is going to.
<?php
if (isset($data['page'])) {
$_SESSION['shoutbox_page'] = intval($data['page']);
}
$redirect = ltrim(str_replace('#', '?', $data['redirect']), '/');
redirect_to($redirect);
Div that contains the content to be refreshed.
<div id="shoutbox_container">
<?php relativeInclude( 'views/shoutbox/shoutbox'); ?>
</div>
jQuery
$('#shoutbox_arrows ul li a').click(function (event) {
event.preventDefault();
$.post('views/shoutbox/' + $(this).attr('href'), function (data) {
$('#refresh_me').load(location.href + " #refresh_me>", "");
$('#shoutbox_arrows').load(location.href + " #shoutbox_arrows>", "");
});
});
So I guess to clarify the issue:
The shoutbox_container displays posts for the shoutbox. The page is controller by a session that gets passed as a variable to get the correct chunk of posts to show. Clicking on the links in shoutbox_arrows sends an ajax request to a page which changes the session variable. The div that contains the post itself (refresh_me) as well as the arrows (for the links) get refreshed. After changing the page once, the shoutbox is no longer connected to the javascript file so when you click to change the page again, instead of an ajax request, the page itself actually changes to the link.
Any ideas how I can fix this? I've spent a lot of time on this and it's getting rather frustrating. I feel like I could just settle for it as it is now but it's bugging me too much that it's not working exactly how I intend (although generally it works in terms of changing the pages).
Also just a note, I used jsfiddle to tidy up the code but it looks like it did some funky stuff (looking just at $current_page=s tr_replace). lol. So there aren't any syntax errors if that's what you're thinking. ><
Also I was going to set up a fiddle but I don't really know how to handle links in it so it would have been useless.
The issue is that you bind the click handler to the a tags on document ready (the jQuery code you provided). So when you replace the content of #shoutbox_arrows you remove the click handler you previously attached since those original handlers are removed from the DOM along with the original elements.
You need to use the jQuery .on() method and event bubbling. This will attach the handler on a parent element that will not be removed in your content replace and can continue to "watch" for the event to bubble up from it children elements.
Try replacing your jQuery code with this:
$('#shoutbox_arrows').on('click', 'ul li a', function (event) {
event.preventDefault();
$.post('views/shoutbox/' + $(this).attr('href'), function (data) {
$('#refresh_me').load(location.href + " #refresh_me>", "");
$('#shoutbox_arrows').load(location.href + " #shoutbox_arrows>", "");
});
});
For performance, you should add a class to the a, and targeting it directly with $('a.aClass')
Good ways to improve jQuery selector performance?

Display Terms of service in any place (Joomla/Virtuemart 2.x)

I have some toruble with displaying terms of service.
At the cart page all works fine: http://mtxt.ibroken.ru/component/virtuemart/cart.html?Itemid=0
(bottom link) opens popup with text, generated by
<?php echo $this->cart->vendor->vendor_terms_of_service; ?>
code.
But i have button on the shop page http://mtxt.ibroken.ru/magazin.html (top button at right side), which must display same text...
At present moment text written in /modules/mod_virtuemart_cart/tmpl/default.php file. But how to get it in this file from shop interface by using PHP?
pps. Ugly English, sorry for that :)
You need to modify /modules/mod_virtuemart_cart/tmpl/default.php (or your override) and add this code just after line 3:
vmJsApi::js ('facebox');
vmJsApi::css ('facebox');
$document = JFactory::getDocument ();
$document->addScriptDeclaration ("
jQuery(document).ready(function($) {
$('div#full-tos').hide();
$('a#terms-of-service').click(function(event) {
event.preventDefault();
$.facebox( { div: '#full-tos' }, 'my-groovy-style');
});
});
");
And add this code just after line 53
<div class="show_cart">
<?php
if(!class_exists('VirtueMartModelVendor'))
require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'vendor.php');
$vendor = VmModel::getModel('vendor');
$vendor = $vendor->getVendor();
?>
<br />
<span style="z-index: 0;">
<a href="<?php JRoute::_ ('index.php?option=com_virtuemart&view=vendor&layout=tos&virtuemart_vendor_id=1') ?>" class="terms-of-service" id="terms-of-service" rel="facebox" target="_blank">
<?php echo JText::_ ('COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED'); ?>
</a>
</span>
<div id="full-tos">
<h2><?php echo JText::_ ('COM_VIRTUEMART_CART_TOS'); ?></h2>
<?php echo $vendor->vendor_terms_of_service; ?>
</div>
</div>
That shoud do the trick!

WordPress child nav a:current styling

I'm currently working on a site for a client - It is all working fine but within the navigation I have setup of for the child links using the following code
<div id="sub_nav_del">
<h4>Take a seat</h4>
<?php
$subnav_parent = ($post->post_parent) ? $post->post_parent : $post->ID;
$pages = get_pages('child_of=' . $subnav_parent . '&sort_column=menu_order');
$count = 0;
foreach($pages as $page)
{ ?>
<ul>
<li>
<h5 class="del">
<a href="<?php echo get_page_link($page->ID) ?>" ><?php echo $page->post_title ?></a>
</h5>
</li>
</ul>
<?php
}
?>
</div>
You can see an example at http://www.lagourmetteria.co.uk/take-a-seat/wine-room/, for that page I would like the current pages link orange.
I would like it to make the current link to be a different colour just within the child navigation. Is there a simple way to do this, unfortunately my PHP skills aren't fantastic.
You already have what you need as a class in the <body> which is wine-room (probably the slug). So in your CSS you can do the following magic:
body.wine-room a[href*="wine-room"],
body.tasting-room a[href*="tasting-room"],
body.food-drink-menu a[href*="food-drink-menu"],
body.have-it-all-private-parties a[href*="have-it-all-private-parties"]
{
color: orange !important;
}
UPDATE
Added all slugs on that submenu.
UPDATE 2
Added !important to supersede any other style.

Categories