Big Bagel
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Show/Hide div in loopThe error I pointed out earlier is still there:
<a href="#" class"show">
Of course, should be:
<a href="#" class="show">
That alone would cause the jQuery example I gave to not work. ??
You currently have this in your
<head>
:<script type='text/javascript' src='https://scottcarltonblog.net/author-toggle.js'></script>
However, there’s no file at that location and it appears to be directly added to your theme’s
header.php
rather than included the proper way withwp_register_script
andwp_enqueue_script
in your theme’sfunctions.php
. Did you already remove that code?You current jQuery is targeting all
<a>
tags which is probably not what you want. Did you want two separate buttons for opening and closing (like you have now) instead of a single button that toggles (like your example link)?Forcing only one div open at a time isn’t too hard but before I recommend anything it would best to finalize this part.
Forum: Fixing WordPress
In reply to: Show/Hide div in loopThat’s enough to see how everything is structured. ??
So, when the title and image that goes along with it (currently wrapped in an
<a>
) is clicked, the “hidden”<div>
should toggle on and off? Will there be multiple copies of this code on the same page or only one? As I mentioned earlier, you probably want to go with jQuery. Here’s an example that should work with the code you gave:jQuery( document ) . ready( function( $ ) { $( '.show' ) . click( function() { $( this ) . next( '.hidden' ) . slideToggle( 'fast' ); } ); } );
This essentially says, when the page is done loading, if somebody clicks on any element with the class “show”, that the following element with the class “hidden” should be toggled.
You can put that in a separate file, upload it wherever you want (probably in your theme’s folder) then simply include it in whatever page you want it to work on. For example, if you name it
author-toggle.js
and put it directly in your theme’s folder (wp-content/themes/your-current-theme
) then, to include it, you can add something like this to your theme’sfunctions.php
:add_action( 'wp_enqueue_scripts', 'add_my_js' ); function add_my_js() { wp_register_script( 'my-author-js', get_template_directory_uri() . '/author-toggle.js', array( 'jquery' ), false, true ); wp_enqueue_script( 'my-author-js' ); }
If you wanted to only have the script load on certain pages you can wrap it up in a conditional. For example, if you only wanted it on the page with ID = 7, then:
add_action( 'wp_enqueue_scripts', 'add_my_js' ); function add_my_js() { if ( is_page( 7 ) ) { wp_register_script( 'my-author-js', get_template_directory_uri() . '/author-toggle.js', array( 'jquery' ), false, true ); wp_enqueue_script( 'my-author-js' ); } }
Here are reference pages to some of the things I used in my examples:
Function Reference/wp register script
Function Reference/wp enqueue script
Function Reference/get template directory uri
https://api.jquery.com/slideToggle/
https://api.jquery.com/next/Of course, if you plan on editing a theme, it’s always a good idea to use a child theme:
If you do use a child theme, my example for
functions.php
might need a little altering depending on where you upload the JavaScript file.Also, it was probably just lost in the move to pastebin, but make sure there’s an equals in there:
<a href"#" class"show">
Once you get a working page up I’ll be happy to troubleshoot any problems. I haven’t exactly tested may examples to make sure there aren’t any errors. ??
Forum: Fixing WordPress
In reply to: Show/Hide div in loopIf providing a link to the site is possible, that would be super helpful. Without actually seeing the structure of the site and exactly what you want hidden/shown it’s hard to suggest anything specific.
Forum: Hacks
In reply to: How do i combine POSTS and PAGES in one listing?It depends on exactly where you want to do this and how you want them displayed, but you can start by creating a custom query that returns both posts and pages:
$args = array( 'post_type' => array( 'post', 'page' ) ); $my_query = new WP_Query( $args );
You can find other parameters here:
https://codex.www.ads-software.com/Class_Reference/WP_Query#Parameters
Then you would just loop through the returned posts/pages and display them however you want.
Forum: Hacks
In reply to: Custom Menu Classesget_post_custom
only takes one argument and always returns an array.Function Reference/get post custom
I think you’re looking for
get_post_meta
:$color = get_post_meta( $item->object_id, 'color', true );
Forum: Fixing WordPress
In reply to: Show/Hide div in loopI’m aware of
strip_tags
. I’m assuming the OP’s code is being included directly in the theme (inheader.php
for example). It wouldn’t be run through any functions sostrip_tags
isn’t an issue.Additionally, the JavaScript should be in a separate file, the file called in the head or footer removing any such issues.
I know, but we weren’t taking about that. The OP’s code was obviously being included directly in the file, so I constrained my recommendations to such. My offer to give a jQuery example, if taken, would have included this fact.
I also disagree about validation issues, if a page is not able to be validated based on the DOCTYPE called, it can and will cause issues.
I never said validation issues should be ignored. I simply said that the only issue with accidentally using the wrong technique in this very specific case would be that it won’t validate. In other words, it will still work as expected in all relevant browsers. Further, since we can’t check the DOCTYPE of the OP’s theme anymore, this doesn’t really matter.
Commenting JavaScript in this fashion was required a very long time ago, but unless you are running Netscape 1 or IE4, it’s not required and can cause validation issues are even be stripped out confusing WP.
I know…that’s what I’ve been saying. From my previous posts:
However, it is true that since practically every browser used today can understand JavaScript, there’s no real reason to do it anymore.
With the browsers used today it’s best just to not use either.
Since these posts don’t have much of anything to do with the OP’s original topic it would be best to continue asking questions in a new topic or, if you want to direct them specifically towards me, on my site.
Forum: Fixing WordPress
In reply to: How can I remove the textbox/form from my page?To check how many queries your site is currently running, you can use this:
Function Reference/get num queries
The easiest way to see every query being run on your site would be this plugin:
https://www.ads-software.com/extend/plugins/debug-queries/
You don’t have to mess with core code to use hooks and filters. In fact, that’s specifically why they exist. You use them in a plugin or your theme’s
functions.php
. Altering the main query isn’t something an average user would do at all.query_posts()
is the standard function to alter the main loop. I was specifically pointing you to this bit of information which is general to WordPress:…WordPress will have already executed the database query and retrieved the records by the time it gets to your template page (that’s how it knew which template page to serve up!).
…such as modifying the default request directly (before it’s called). The request filter can be used to achieve exactly this.
–
Do your theme(s) use this?
I’ve built themes and plugins with several opportunities to use
query_posts()
and filters to alter the main query. ??Since these posts don’t have much of anything to do with the OP’s original topic it would be best to continue asking questions in a new topic or, if you want to direct them specifically towards me, on my site.
Forum: Fixing WordPress
In reply to: How can I remove the textbox/form from my page?The code for the main query is within the core WordPress code. The best way to alter it before it executes is by hooking into an early enough action. By the time WordPress hits the actual theme template for the page being shown it has already run the necessary query to pull whatever post(s)/page content it needs. If you try to alter it within a template file, it will simply run a completely new query.
Removing/editing a function that is declared within a theme isn’t quite the same.
Forum: Fixing WordPress
In reply to: Show/Hide div in loopThe DOCTYPE is completely up to the theme (look in
header.php
). Plus, using the wrong example won’t break anything other than validation. With the browsers used today it’s best just to not use either.And what about stripping HTML tags?
What?
Forum: Fixing WordPress
In reply to: How can I remove the textbox/form from my page?WordPress itself runs through all the normal queries before hitting the proper template file. It’s how it knows which file to use. Unless your adding additional queries or doing something out of the ordinary, the actual code within templates is relatively light. Yes, you can create and use a custom template or alter the proper part of the theme…but that’s not exactly what you suggested. ??
No, template files don’t need to use any PHP. It is good form to include the theme’s header and footer though.
Most page caching plugins will already serve cached static HTML pages regardless of how the original page was created. So, except for saving a tiny bit of processing time when the cache is re-built, it doesn’t really matter how static the original uncached page is.
If this is going to be a permanent (rather than temporary) landing page, the OP could always use a normal HTML file and install WordPress in a subdirectory. Considering that this page doesn’t require any WordPress related functionality and is considerably different from the theme being used this is probably the best thing to do.
Forum: Fixing WordPress
In reply to: Show/Hide div in loopThat’s how you would do it if you were using XHTML, right above it is the example for HTML like the OP’s code example:
https://en.wikibooks.org/wiki/JavaScript/Placing_the_Code#Inline_HTML_comment_markers
Forum: Fixing WordPress
In reply to: Show/Hide div in loopWrapping JavaScript in an HTML comment used to be standard practice to keep browsers that didn’t support JavaScript from having problems. The JavaScript inside will still run regardless. However, it is true that since practically every browser used today can understand JavaScript, there’s no real reason to do it anymore.
The problem is that your script is probably targeting your entire content section. The best way to toggle specific content is by using jQuery. If you’re trying to show/hide individual posts, you can give a link to your site and I’ll try to come up with a working code example; it shouldn’t be too hard. If you’re looking to hide content within a post/page you can also check out this plugin:
https://www.ads-software.com/extend/plugins/jquery-collapse-o-matic/
Forum: Fixing WordPress
In reply to: How to remove categories from nav bar?It’s theme dependent. Your theme had extra stuff such as a search form and categories wrapped up with your nav menu. Most themes will only have
wp_nav_menu
,wp_page_menu
, or a custom function. Deleting them will result in a loss of the entire nav menu. Since this is a premium theme which provides a built-in way of organizing the menu items, I would assume it’s using a single custom function rather than one for pages and one for categories.Forum: Fixing WordPress
In reply to: How can I remove the textbox/form from my page?My first CSS example doesn’t really hide anything, it just overrides the backgrounds and borders around the text. As for hiding everything in my second example, yes the content is still being created. However, WordPress runs all its queries before reaching the specific template, so even if you removed the loop, the actual processing time and resources needed to create the page would be about the same.
Again, you can’t simply “Remove the elements in the <body> tag” because the page doesn’t actually exist in that form. You can alter the theme or create a custom page template though, which is what I mentioned at the bottom of my previous post. ??
Would the text be a part of the image or the actual WordPress page content? It looks like you switched over to HTML pages for now. If you want to try again with WordPress, I’ll be happy to look around for what went wrong.
If this is only a temporary placeholder page, you could also consider one of these plugins:
https://www.ads-software.com/extend/plugins/custom-coming-soon-page/
https://www.ads-software.com/extend/plugins/wp-maintenance-mode/Forum: Fixing WordPress
In reply to: How can I remove the textbox/form from my page?Since it’s an actual WordPress page, you can’t really do that…
Unless you’re suggesting altering
single.php
or using a custom page template.What exactly are your looking to get rid of? Everything except the text or absolutely everything? I would assume since you want to “write directly onto the background image,” you still want the text to be visible?
Also, will this be the only page on the site? If there will be other pages do you want this to apply to every page or just the front page?
If you’re looking to get rid of everything but the text on your home page something like this added to your theme’s
style.css
would do it:.home div.clearstyle_c1_alt, .home div.clearstyle_c2, .home table.clearstyle-title { background: none; } .home #content table, .home #content tr td, .home table.clearstyle-title { border: none; }
If you want to hide everything but the background image you can use this instead:
.home #main { display: none; }
Using a child theme to edit a theme’s code is always a good idea:
As mentioned earlier you could also create a custom page template that shows whatever you want, then set your static front page to use it:
https://codex.www.ads-software.com/Pages#Page_Templates
If you create a template named
front-page.php
it will be used automatically for your site’s front page.