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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: