Sticky navigation script wont attach class to div - php

I am currently editting a wordpress theme and creating a navigation bar half way the page that sticks to the top of the screen once the user scrolls past a certain point. Ive done this before and it worked fine. I copied that exact code and changed the #divs and classes to the correct ones. This is the code i use:
$(window).scroll(function () {
console.log($(window).scrollTop())
if ($(window).scrollTop() > 10) {
$("#stickbar-steps").addClass("after-scroll-wrap");
}
if ($(window).scrollTop() < 9) {
$("#stickbar-steps").removeClass("after-scroll-wrap");
}
});
However it doesn't seem to add the class to the #div.When i manually add the class to the #div it works fine but it just wont load the script or wont attach the class. Usually when i reach that point in my previous working one, i could see it getting attached using inspect element, but im not seeing it in this one.
The wordpress theme has a seperate page in the admin section which allows me to paste in JS code. I've tried to add it there and i've tried to paste a copy among the other jquery files in the functions.php. But neither of them seems to work.
Any ideas where to look for? Theme uses jquery ver=1.12.4.
Thanks

Related

Why is the WordPress customizer live preview breaking if I don't check if the function exists?

I'm trying to add the "custom background" support for a theme I'm building, so that users can change it in Appearance > Customize > Colors. The button is showing up, and it's working, BUT the color is not displaying in the live preview.
When I inspect the iframe, WordPress is not adding the "custom-background" body tag, and it's not adding the CSS in the head section of the document.
After hours of digging around, I noticed that one of my php files used as a template file contains a function definition. If I check if the function exists, the live preview magically starts working. This works:
if ( ! function_exists( 'posted_on' ) ) {
function posted_on() {
// Stuff here
}
}
This, on the other hand, breaks the live preview:
function posted_on() {
// Stuff here
}
Does anybody have any idea why is this happening? Why is omitting the check for the function name breaking the customizer's live preview? I checked the page source code in an HTML validator and it does not have any errors.
Thanks

Changing Logo on Scroll with PHP/jQuery

Ello there,
First of all thanks for any help, it's appreciated.
What I am trying to do is change my website's logo on scroll, but I am trying to accomplish this through my theme options, and I am not looking to use CSS to hide/show a class which uses the background property to display the logo.
Instead in my header.php I am echoing a function which renders the logo dependent on what "header option" a user has selected.
Here is the PHP I have which works on a switch inside my admin panel, so if a user selects "Yes" and they would like to change the logo when the header is sticky then they have an option to upload an extra logo (this all works fine without checking if that css class exists):
$site_logo_change_scroll_switch = notorious_options('site_logo_change_scroll_switch');
if ( $site_logo_change_scroll_switch == true && class_exists('scrolled-nt') ) {
$logo_url = notorious_options('site_logo_change_scroll', false, 'url');
}
return $logo_url;
This code is all working fine, except for checking if the CSS class "scrolled-nt" exists to only display this logo on scroll. I am using Jquery to append this class to my logo:
jQuery(window).scroll(function(){
var fromTopPx = 5;
var scrolledFromtop = jQuery(window).scrollTop();
if(scrolledFromtop > fromTopPx){
jQuery('.nt-logo').addClass('scrolled-nt');
}else{
jQuery('.nt-logo').removeClass('scrolled-nt');
}
});
I can see on my website, that when I scroll down the extra CSS class "scrolled-nt" is added onto my img src, but the logo is not showing at all after or before scroll, with checking if this CSS class exists (in my php above).
Any idea what I'm doing wrong here?
I hope I explained this properly, and maybe it is a simple fix, but I am fairly new to JS/PHP and quickly getting an addiction for it.
Any helps appreciated, thanks!

whmcs module clientarea page per bought product

so I have 2 modules one working(paid for not encrypted)learned a lot from it lets call this the reference_module and I have my own module which was a PHP page which I am rebuilding for WHMCS and it is almost working completly lets call it created_module.
the problem right now I have is the reference_module is called by when going to https://domainwhmcs.nl/clientarea.php?action=productdetails&id=0001&reference
which is working and shows what I want:
the normal header
normal sidebar
normal footer
and its own content in the main content area
it does this by using hooks having ReferenceClientareaheaderoutput and ReferenceClientareapage which works.
so now I tried to recreate this in created_module but when going to https://domainwhmcs.nl/clientarea.php?action=productdetails&id=0001&created which is working but shows me:
its own content
just its own content but I want the same as in Reference.
I think if I am going to paste the code the post will be to long if needed maybe I can post specific parts.
Allread thanks for helping
so I actualy did solve it today you have to use javascript
jQuery.post("index.php",{"action":'dbinfo',"user":username,"serviceid":serviceid},
function(data){
jQuery(".main-content").html(data);
jQuery("#tabs li").removeClass("active");
jQuery("#tabs li").eq(index).addClass("active");
and
if (isset($_POST['action']) && $_POST['action'] == "dbinfo") {
this you do in your module hook if you need help you can contact me

Adding a javascript to all pages in OpenCart

I'm new to OpenCart and don't have any experience with PHP, so I have a question. I want to add the following JavaScript to hide the url bar on mobile browsers
// When ready...
window.addEventListener("load",function() {
// Set a timeout...
setTimeout(function(){
// Hide the address bar!
window.scrollTo(0, 1);
}, 0);
});
However, I can't find a way to insert this so this code will be executed on all pages in OpenCart. Where should I put this code?
save your script to a file, say 'catalog/view/javascript/myscript.js'
Then add
$this->document->addScript('catalog/view/javascript/myscript.js');
to the catalog/controller/common/header.php some place before this line:
$this->data['scripts'] = $this->document->getScripts();
You could also just place your script inline into catalog/view/theme/{theme name}/template/common/header.tpl using normal html markup.
Looking at the theme documentation, I believe you want to edit the following file:
catalog/view/theme/{your-theme}/template/common/header.tpl
These templates (header, footer, etc) should appear on all pages.
You don't need to go through this trouble especially if you don't have access to FTP. All you need to do is just go to admin panel > design > theme editor > and choose the respective parts to insert the codes. If is footer then just choose footer.twig.
After adding the codes, click Save and you will see the changes immediately. If add the codes directly to the file on FTP, it won't work.
Tried and tested on OpenCart 3
To add a script like that, just go to admin panel > design > theme editor > select "common" > footer and in the end of the file (after </html>) add the script.
If you want script to all your pages of the OC just add it before footer tag in footer.tpl or footer.twig

Wordpress can't find php file in correct directory

I'm getting into wordpress and I've been following some pretty good tutorials and reading through the codex but I've encountered a problem which I can't seem to find the answer to anywhere else. Eventually my plan is to create an interface for users of my theme that will allow them to change colors, widths, positioning, etc. of certain elements in the template. Basically it will be a php file that will generate a css document. For right now though all it does is echo a sentence. I'm not sure if this is technically a "plug-in" but when I try to put it in the plugins folder, I end up with a 404 error. I know the file is there and I have triple checked the path. I have also tried navigating to the php file directly in the url but I still get a 404 error. I have also tried using the plugin template. It echoes the sentence when I click "activate" in the plugins manager, but it does not work at all when calling it from the functions.php file. Any help is greatly appreciated.
Here is the code which I have placed at the end of my functions.php:
//begin template specific*******************************************************
//------the function below styles the wordpress admin menus.-------
function custom_style() {
echo '<style type="text/css">#adminmenu .wp-menu-image img {padding: 0px !important; margin-left: -3px;}</style>';
}
add_action('admin_menu', 'register_custom_menu_page');
add_action('admin_menu', 'custom_style');
//------this function adds the template specific menu item.---------
function register_custom_menu_page() {
add_menu_page('Epsilon', 'Epsilon', 'add_users', plugins_url('epsilon/eps-manage.php', eps-manage.php ), '', content_url('themes/epsilon/images/eps-icon.png'), 6);
} // this function creates the correct path as far as I can tell, but when I click the link button in the admin menu, I get the 404.
//------this function hides the editor option under the appearance menu ----------
function remove_editor_menu() {
remove_action('admin_menu', '_add_themes_utility_last', 101);
}
add_action('_admin_menu', 'remove_editor_menu', 1);
Why am i getting this 404 error and is there a more correct way to do this?
You are trying to merge a plugin and a theme. plugins_url will only load up the file of a registered and activated (not sure on the activation 100%) plugin, As you are developing a theme it is better to have your management files relative to your theme folder, but to be honest for this type of job as you are a begginer I would keep everything in functions.php and use functions as the callbacks to your menus.

Categories