Connect with us
The intuitive design of ledger live desktop wallet software simplifies the process of managing and trading cryptocurrencies, offering users a secure and user-friendly experience within the decentralized finance ecosystem.

Tips & Tricks

How to: show/hide a widget in WordPress with jQuery

In a previous post I talked about how to show/hide a single div html code with a search inside. Today I’d like to show you how I implemented jQuery into my new theme.

Published

on

As seen in the current theme, I am using jQuery to animate the show/hide or as known as the css style display: none;.

Since I am using a custom child theme on my site, and have Hybrid theme as my parent, the widgets or sidebar section is different than may be in your theme. But just apply the the style’s as follows to your theme.

First make sure that your WordPress site is calling jQuery, by plugging in this code into your header.php file above the <?php wp_head(); ?> text:

<?php wp_enqueue_script('jquery'); ?>

Then anywhere above the </head >, plug this code in:

<script type="text/javascript">
function toggleWidgets() {
	$('#primary h3.widget-title').addClass('plus');

	$('#primary h3.widget-title').click(function() {
		$(this).toggleClass('plus').toggleClass('minus').next().toggle(180);
	});

}
$(document).ready(function() {
	toggleWidgets();
}
</script>

That’s it. Pretty simple huh.

So lets go over what the code does.

$('#primary h3.widget-title').addClass('plus');

This line finds all <h3> tags with the class widget-title inside the ID parameter of #primary and adds a class of plus.

Then

$('#primary h3.widget-title').click(function() {
		$(this).toggleClass('plus').toggleClass('minus').next().toggle(180);
	});

Will apply a click function. When the H3 tag is clicked it will remove the class plus and add the class minus.

Then the code that says .next will then toggle the “next” element after the <h3> title.

Continue Reading
9 Comments

9 Comments

  1. Rolograaf

    July 29, 2009 at 5:59 am

    Tried this, saw the javascript in the source of my blog, but the plus class was not added and click function not activated. Any idears what I could have done wrong?

    • Alik

      September 14, 2009 at 7:27 am

      Same problem here. In Firebug th script is there, but the class is not added to h3 widget class inside div ID primary.

      Any ideas?

      • Austin

        September 15, 2009 at 12:40 pm

        Example links?

        • Alik

          September 18, 2009 at 5:40 pm

          http://accio.website.pl/ozo/
          code is working now (I think so 😉 ) but the CSS class/definition for hide/unhide panels is missing (?).
          .-= Alik´s last blog ..Import blogu z blox.pl do WordPress =-.

          • Chris

            September 28, 2009 at 9:22 pm

            Doesn’t work for me. I don’t see the class added. I have the last jquery installed, I even tried the noConflict just in case and nothing.

  2. Pingback: 30 Tutorials Combining Both Wordpress and jQuery : Speckyboy Design Magazine

  3. Pingback: 30 Tutorials Combining Both Wordpress and jQuery | Coyot [at] CanalCoffee.com : WordPress

  4. Pingback: 30 tutorial para utilizar jQuery en nuestro Wordpress | code

  5. Pingback: 20+ jQuery and Wordpress Tutorials – A Match Made in Heaven

You must be logged in to post a comment Login

Leave a Reply

Tips & Tricks

Can′t add pagination on WooThemes Thick Theme

Published

on

Everything I have tried has led to nothing. And I have tried six way’s from Sunday to get my main posts to paginate.

example one:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
query_posts('offset=1&showposts=' . get_option('woo_other_entries') . '&cat=-' . $GLOBALS['ex_asides'] . '&paged=$paged' ); ?>

example two:

<?php 
global $myOffset; 
global $wp_query;
$myOffset = 1;
$paged = intval(get_query_var('paged')) ? get_query_var('paged') : 1;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query(array(
	'offset' => $myOffset,
	'category__not_in' => array($GLOBALS['ex_asides'],7,84),
	'paged' => $paged,
	'showposts' => get_option('woo_other_entries'),
	)); ?>

example three:

<?php 
global $myOffset;
$myOffset = 1;
$wp_query = new WP_Query();
$wp_query->query(array(
	'offset' => $myOffset,
	'category__not_in' => array($GLOBALS['ex_asides'],7,84),
	'paged' => $paged,
	'showposts' => get_option('woo_other_entries'),
	)); ?>

And after those tries, I just can’t get more pages beyond the option’s that I choose, and can only pull an archive via the browse more link.

Any suggestions or anything?

Continue Reading

Tips & Tricks

Pulling custom fields from outside the loop

Published

on

In the last post “Creating a custom widget” I showed you how to create a custom widget. Well in this post I will show you how I used my custom widget to display all post with a certain custom field from outside the WordPress loop.

In the last post I used this tag:

<?php include(TEMPLATEPATH . '/includes/showcase.php'); ?>

Now I will show you what the file showcase.php has:

<ul>
<?php
global $wpdb;

$sql = "SELECT wposts.*
	FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
	WHERE wposts.ID = wpostmeta.post_id
	AND wpostmeta.meta_key = 'gallery-url'
	AND wposts.post_status = 'publish'
	AND wposts.post_type = 'post'
	ORDER BY wposts.post_date DESC LIMIT 8";

$pageposts = $wpdb->get_results($sql, OBJECT);
$output = $pre_HTML;

foreach ($pageposts as $post) : setup_postdata($post);  ?>

<li><a href="<?php echo get_post_meta($post->ID, "gallery-url", $single = true); ?>" title="Link to <?php the_title(); ?>">
<img src="<?php echo get_post_meta($post->ID, "image", $single = true); ?>" alt="<?php the_title(); ?>" /></a></li>

<?php endforeach; ?>

</ul>

That’s it! The most important item you may want to change for your own custom field is the line : AND wpostmeta.meta_key = 'gallery-url'. Where you would change the text in bold to match your own custom field value.

Update:

Check out Austin from PressedWords comment below.

With his great advise I was able to figure out why all my attempts to use the query_post weren’t working. it came down to this line of code: <?php echo get_post_meta($post->ID, "gallery-url", $single = true); ?>, that was what I had in my code, and the $post->ID is the reason my code would not echo or print the custom field’s value. Solution? replace $post->ID with get_the_ID(). HA, so simple.

Continue Reading

Tips & Tricks

Creating a custom widget

Published

on

Today let’s learn a simple quick trick on how to create a custom widget. For my example I will show you how I created my Showcase widget located in the middle, to the right of the posts.

First under your functions.php file type in the following:

<?php // Custom Widget
function MyCustomWidget() { ?>
<li class="widget">
    <h2 class="heading">Latest Showcase</h2>
        <ul>
        	<?php include(TEMPLATEPATH . '/includes/showcase.php'); ?>
        </ul>
</li>

<?php }

register_sidebar_widget('The Custom Widget for Showcase', 'MyCustomWidget'); ?>
  • Always make sure your code is between the <?php and ?> for it to work.
  • Once we call the function, the rest is assuming html code that you may or may not need.
  • For instance, you may just put in a picture and call it a day. But my code starts with <li< because my sidebar’s start and end with <ul<.
  • Any way, once your done, just set the final “register_sidebar_widget('the widget title', 'the name of the function');

That’s it! Now you have a custom widget with what ever you want!

Continue Reading

Random Search Terms

Title

Recent Posts: Fully Net Worth . com

Hero Fiennes Tiffin Net Worth: How Rich is the English Actor?

Hero Fiennes Tiffin Net Worth: How Rich is the English Actor?

Hero Beauregard Faulkner Fiennes-Tiffin is an English actor and model. He is best known for playing the role of a character named Hardin Scott in the 2019 film called After that was a big hit among the younger audiences. As of 2020, Hero Fiennes Tiffin net worth is estimated to be $700,000. Fiennes was born […]

Cash Nasty Net Worth: How Much He Makes From YouTube?

Cash Nasty Net Worth: How Much He Makes From YouTube?

Cash Nasty is an American Youtuber who is known for running the Youtube channel called WhatChaMaCalling. Moreover, he is also on Twitch where he runs a channel called CashNastyGaming. As of 2019, Cash Nasty net worth is estimated to be $1.5 million. He was born on December 4, 1990  in Vidalia, Louisiana. Nasty has always been […]

DaBaby Net Worth: How Rich is the Rapper Actually?

DaBaby Net Worth: How Rich is the Rapper Actually?

Jonathan Lyndale Kirk, who is better known by his stage name as DaBaby, is an American rapper. He is best known for his hit debut album which was called Baby on Baby and even made it to the number 7 of the reputed Billboard Hot 100. As of 2019, DaBaby net worth is around $3 […]

Payton Moormeier Net Worth: How Rich is the Tik Tok Star Actually?

Payton Moormeier Net Worth: How Rich is the Tik Tok Star Actually?

Payton Moormeier is a social media personality who is best known for his lip-sync videos on the popular platform called TikTok where he has more 8.8 million followers where his videos have received close to 350 million likes which is an absolutely mammoth number, especially considering that he is still only 16 years old. As […]

Trending