We moved to www.wpworking.com

We moved to another dimension - www.wpworking.com

Leave a comment

New Hack for Displaying a Category / Subcategory Menu on WordPress

Visit http://www.wpworking.com/hacks-2/new-hack-for-displaying-a-category-subcategory-menu-on-wordpress/

This post is very similar to the last one, but now we will show also subcategories onthe menu.

Again, you just have to copy and paste the code bellow wherever you want on your theme files.

You can also play with its CSS styles, so using the ids divcateg, ulcateg and the dynamic generated licateg_[category slug], ulsubcateg_[subcategory slug] and licateg_[subcategory slug]. You may change the category / subcategories menu appearance.

<?
$args = array(
'type'                     => 'posts',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'taxonomy'                 => 'category',
'pad_counts'               => false );

$categories = get_categories($args);
if(count($categories)>0):
	echo '<div id="divcateg"><ul id="ulcateg">';
	foreach ($categories as $category) {
		echo '<li id="licateg_'.$category->slug.'"><a href="'.get_bloginfo('siteurl')."/".$category->slug.'">'.$category->cat_name.'</a>';
		$subcategories=  get_categories('child_of='.intval($category->cat_ID));
				foreach ($subcategories as $subcategory) {
					echo '<ul id="ulsubcateg_'.$subcategory->slug.'">';
					echo '<li id="licateg_'.$subcategory->slug.'"><a href="'.get_bloginfo('siteurl')."/".$category->slug."/".$subcategory->slug.'">'.$subcategory->cat_name.'</a></li></ul>';
				}
		echo '</li>';
	}
	echo '</ul></div>';
endif;
?>

,

Leave a comment

New Hack for Displaying a Category Menu on WordPress

Check also this same hack, displaying also subcategories.

Hi there,

If you want to display a menu containing links for every post category page on your WordPress site, probably this hack will be useful.

Just copy and paste wherever you want on your theme files.

You can also play with its CSS styles, so using the ids divcateg, ulcateg and the dynamic generated licateg_[category slug], you may change the category menu appearance.

<?
$args = array(
'type'                     => 'posts',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'taxonomy'                 => 'category',
'pad_counts'               => false );

$categories = get_categories($args); 					 
if(count($categories)>0):
	echo '<div id="divcateg"><ul id="ulcateg">';
	foreach ($categories as $category) {
		echo '<li id="licateg_'.$category->slug.'"><a href="'.get_bloginfo('siteurl')."/".$category->slug.'">'.$category->cat_name.'</a></li>';
	}
	echo '</ul></div>';
endif;
?>

,

1 Comment

WordPress WP-ecommerce Search Page with Related Products Hack

If you are using WP-ecommerce on your WordPress site, what about displaying related products on your theme’s search page?

Just copy and paste the following code on your search.php file, on your theme folder. It will bring as results the title and first image of each product found, linked to the detail page.

<?php
/**
 * @package WordPress
 * @subpackage Toolbox
 */

get_header(); ?>

        <section id="primary">
            <div id="relprods" style="float:left;width:140px;margin-right:20px;">
            <?
            /*
                New code by Alvaron - brings two first product images - 08-22-2011
            */
                $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
                mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
                $sqlp ="select ID, post_title, post_name from wp_posts where post_type='wpsc-product' ";
                $sqlp .="and post_status='publish' ";
                $sqlp .="and (post_title like '%".$_GET['s']."%' ";
                $sqlp .="or post_content like '%".$_GET['s']."%') ";
                $sqlp .="order by id ASC ";
                $qryp = mysql_query($sqlp);
                $nrtp = mysql_num_rows($qryp);
                if($nrtp>0):
                    $mxctst= "max-width:550px";                     
                    echo "<b>".$nrtp. " Related Products for ".$_GET['s'].":</b><br><br>";
                    while($rsp = mysql_fetch_array($qryp)):
                        ++$prdcnt;
                    ?>
                        <p><?=$prdcnt;?>.
                        <a rel="<?php echo $rsp[1]; ?>" href="<?php echo get_bloginfo('siteurl')."/".$rsp[2]; ?>"><?php echo $rsp[1]; ?></a><br />
                    <?
                        $sqli = "select guid from wp_posts where post_type='attachment' and post_mime_type='image/jpeg' and post_parent=".$rsp[0];
                        $sqli .= " ORDER BY ID DESC ";
                        $sqli .= " LIMIT 1 ";
                        $qryi = mysql_query($sqli);
                        $nrti = mysql_num_rows($qryi);
                        while($rsi = mysql_fetch_array($qryi)):
                        ?>                                               
                                <a rel="<?php echo $rsp[1]; ?>" href="<?php echo get_bloginfo('siteurl')."/".$rsp[2]; ?>"><img class="product_image" id="product_image_<?php echo $rsp[0]; ?>" alt="<?php echo $rsp[1]; ?>" title="<?php echo $rsp[1]?>" src="<?php echo $rsi[0]; ?>" width="140"/></a>   
                        <?
                        endwhile;
                        ?>
                        </p>
                        <?
                    endwhile;
                endif;
                ?>
            </div>
            <div id="content" role="main" style="float:left;<?=$mxctst?>">

            <?php if ( have_posts() ) : ?>

                <header class="page-header">
                    <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'toolbox' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
                </header>

                <?php /* Display navigation to next/previous pages when applicable */ ?>
                <?php if ( $wp_query->max_num_pages > 1 ) : ?>
                    <nav id="nav-above">
                        <h1 class="section-heading"><?php _e( 'Post navigation', 'toolbox' ); ?></h1>
                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'toolbox' ) ); ?></div>
                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'toolbox' ) ); ?></div>
                    </nav><!-- #nav-above -->
                <?php endif; ?>
               
                <?php /* Start the Loop */ ?>
                <?php while ( have_posts() ) : the_post(); ?>
                   
                    <?php get_template_part( 'content', 'search' ); ?>

                <?php endwhile; ?>
               
                <?php /* Display navigation to next/previous pages when applicable */ ?>
                <?php if (  $wp_query->max_num_pages > 1 ) : ?>
                    <nav id="nav-below">
                        <h1 class="section-heading"><?php _e( 'Post navigation', 'toolbox' ); ?></h1>
                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'toolbox' ) ); ?></div>
                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'toolbox' ) ); ?></div>
                    </nav><!-- #nav-below -->
                <?php endif; ?>               

            <?php else : ?>

                <article id="post-0" class="post no-results not-found">
                    <header class="entry-header">
                        <h1 class="entry-title"><?php _e( 'Nothing Found', 'toolbox' ); ?></h1>
                    </header><!-- .entry-header -->

                    <div class="entry-content">
                        <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'toolbox' ); ?></p>
                        <?php get_search_form(); ?>
                    </div><!-- .entry-content -->
                </article><!-- #post-0 -->

            <?php endif; ?>

            </div><!-- #content -->
        </section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Leave a comment

WordPress WP-ecommerce Two Images Hack on Single Product Page

Have you ever thought about displaying two or more images on your wpsc-single_product.php file instead of just one?

If you need to display more than one image, you just have to add this code to the single product page, changing values for LIMIT on the SQL query as you want.

Probably you will want to comment the thumbnail original code. It is right after the line with this conditional

<?php if ( wpsc_the_product_thumbnail()) : ?>

Well, here goes the hack.

<?
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
$sql = "select guid from wp_posts where post_type='attachment' and post_mime_type='image/jpeg' and post_parent=".wpsc_the_product_id();
$sql .= " ORDER BY ID ";
$sql .= " LIMIT 2 ";
$qry = mysql_query($sql);
$nrt = mysql_num_rows($qry);
while($rs = mysql_fetch_array($qry)):
?>
    <a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo $rs[0]; ?>">
            <img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo $rs[0]; ?>" width="280"/>
        </a>
<?
endwhile;
?>

Leave a comment

How to Hide Add New Buttons For a WordPress Specific Custom Post Type on Wp-Admin

Sometimes, when you register a custom post type, you may want to hide “add new” buttons on wp-admin menu and edit page, to keep a fixed number of posts to be managed by the user without changing the original website concept or design.

Just paste the code bellow on your theme functions.php file, and the “add new” buttons will be hidden from wp-admin users.

// hide "add new" on wp-admin menu
function hd_add_box() {
  global $submenu;
  unset($submenu['edit.php?post_type=yourcustomposttype'][10]);
}

// hide "add new" button on edit page
function hd_add_buttons() {
  global $pagenow;
  if(is_admin()){
	if($pagenow == 'edit.php' && $_GET['post_type'] == 'yourcustomposttype'){
		echo ".add-new-h2{display: none;}";
	}  
  }
}
add_action('admin_menu', 'hd_add_box');
add_action('admin_head','hd_add_buttons');

Leave a comment

How to Change The Logo on WordPress Wp-Admin Login Page

Paste this simple code on your theme functions.php file to change the logo that is displayed for users on wp-admin login page.

function cs_loginimg() {
	  echo '<style type="text/css">
	    h1 a {background-image: url('.get_bloginfo('template_directory').'/images/login.gif) !important; }
	  </style>';
}
add_action('login_head', 'cs_loginimg');

Leave a comment

How To Display Custom Help Box On WordPress Wp-Admin

Have you ever thought about displaying custom messages or help tips for site users on wp-admin?
Add this simple code to your theme functions.php file and a custom help box will be displayed on wp-admin.

add_action('wp_dashboard_setup', 'custom_dashb_add');
function custom_dashb_add() {
	global $wp_meta_boxes;
	wp_add_dashboard_widget('custom_help', 'Help!', 'custom_dashb');
}
//
function custom_dashb() {
	echo "<div>
			<ul style='list-style:disc;margin-left:25px;margin-right:10px;padding-top:10px'>
        		<li>Text item for tour custom help</li>
    		</ul>
    	</div>";
}

Leave a comment

The New WP e-Commerce List Products and Images Hack

This post was moved to http://www.wpworking.com/hacks-2/the-new-wp-e-commerce-list-products-and-images-hack/


Well, this code bellow is what I call a “Chewbacca” code, but it works.

I present you the new hack to list products data and images where you want on your theme, if you are working with WP-ecommerce on WordPress.

It was tested on 3.8.5 version, and worked like a charm. If you are using older versions, check the old hack.

Also check WP e-Commerce Product Showroom 2.0.0 on the plugin menu.

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
// if you are note sure about the value of $wp_table_prefix, perform a search for this
// text on your site, the usual value is "wp_" or something
$sql = "select pt.ID, pt.post_title from wp_posts As pt  ";
$sql .= "LEFT JOIN wp_postmeta As mt ON pt.ID=mt.post_id  ";
$sql .= "WHERE pt.post_type = 'wpsc-product' ";
$sql .= "AND pt.post_status = 'publish' ";
$sql .= "GROUP BY mt.post_id ";
$sql .= "ORDER BY pt.post_title ";
$sql .= "LIMIT 3 ";
$qry = mysql_query($sql);
$nrt = mysql_num_rows($qry);
while($rs = mysql_fetch_array($qry)):
//
$sqlp = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqlp .= "where wm.meta_key='_wpsc_price' and wm.post_id=".$rs[0];
$sqlp .= " GROUP BY wm.post_id";
$qryp = mysql_query($sqlp);
while($rsp = mysql_fetch_array($qryp)):
	$prc = $rsp[0];
endwhile;
//
$sqli = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqli .= "where wm.meta_key='_thumbnail_id' and wm.post_id=".$rs[0];
$sqli .= " GROUP BY wm.post_id";
$qryi = mysql_query($sqli);
while($rsi = mysql_fetch_array($qryi)):
	//
	$sqlt = "select guid from wp_posts where ID=".$rsi[0];
	$qryt = mysql_query($sqlt);
	while($rst = mysql_fetch_array($qryt)):
		$pht = $rst[0];
	endwhile;
endwhile;


$htmlcod .= "<div class='showrpdiv'>\n";
$htmlcod .= "<ul>\n";
$htmlcod .= "<li><a href=".wpsc_product_url($rs[0]).">".$rs[1]."</a><br>";
$htmlcod .= "<a href='".wpsc_product_url($rs[0])."'>";
$htmlcod .= "<img src='".$pht."' style='width:".$tbwid."px'></a>\n";
$htmlcod .= "</li>\n";
$htmlcod .= "<li>".$prc."</li>\n";                   
$htmlcod .= "</ul>\n";
$htmlcod .= "</div>\n";

endwhile;

echo $htmlcod;

11 Comments

WordPress Wp-Admin Menu Hack – Hide Menus From Specific User

Hi there,

If you want to hide menus from a specific user on wp-admin, you can use this hack.

I’ve used the example bellow combined with Role Manager Plugin to hide all the wp-admin menus, displaying just “Comments” for the user.

$user_id = get_current_user_id();
//echo "user:".$user_id;
if ($user_id == 2) {
	function remove_menus () {
	global $menu;
			$restricted = array(__('Dashboard'), __('Agenda'), __('Downloads'), __('Galerias'), __('Depoimentos'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'),  __('Plugins'));
			end ($menu);
			while (prev($menu)){
				$value = explode(' ',$menu[key($menu)][0]);
				if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
			}
	}
	add_action('admin_menu', 'remove_menus');
}

Just put this code on functions.php.

Leave a comment