Posts Tagged postaweek2011

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 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

Quick solution to display a menu like list of WordPress Custom Post Type Posts(with Custom Taxonomy) in case of emergency

Well, I was in a hurry, the customer needed to have his site working as soon as possible, and I had to display a menu like list of WordPress Custom Post Types working for three different languages, but I didn’t have time to think of a elegant way to make it work. So I’ve created this little hack, that checks the custom taxonomy for each post and uses a conditional to decide what happens as a quick solution, and I’m sharing with you, to use in a case of emergency 🙂
Bem, eu estava com pressa, o cliente precisava ter seu dite funcionando o mais rĂĄpido possĂ­vel, e eu tinha que exibir uma lista tipo menu de Tipos de Posts Customizados WordPress funcionando para trĂȘs diferentes idiomas, mas eu nĂŁo tinha tempo para pensar em um jeito elegante de fazer funcionar. EntĂŁo criei este pequeno hack que verifica a taxonomia customizada para cada post e decide o que acontece usando uma condicional como uma solução rĂĄpida, e estou compartilhando com vocĂȘs, para usarem em caso de emergĂȘncia 🙂

<ul class="submenu">
   <?
   // here it's the query for my custom post type - Movies 
   $querycp = array( 'post_type'=>'Movies','posts_per_page' => -1 );
   query_posts($querycp);
   while (have_posts()) : the_post();
   // here we check what's the post custom taxonomy, if it is the language we need
   $terms = get_the_terms(get_the_ID(), 'movies_cat');
    foreach ( $terms as $term ) {
        $catref = $term->slug;
    }
   //
     if($catref=="english"):
     ?>
      <li><a href="<?=get_permalink()?>" title=""><?=get_the_title()?></a></li>
     <?
     endif;
   endwhile;
    ?>
</ul>

,

2 Comments

How to reset queries on WordPress

Sometimes you may want to reset WordPress queries, when you are working on a page that displays data from posts of different categories mixed with custom post types, for example(two or more queries on the same page).
Às vezes, talvez vocĂȘ queira resetar suas queries WordPress, quando vocĂȘ estĂĄ trabalhando em uma pĂĄgina que exibe informaçÔes de posts de diferentes categorias misturados Ă  tipos de posts customizados, por exemplo(duas ou mais queries na mesma pĂĄgina).

In this case, all you have todo is use wp_reset_query(); after each loop.
Neste caso, tudo que vocĂȘ deve fazer Ă© usar wp_reset_query(); depois de cada loop.

If you have any doubt, just check the Codex.
Se vocĂȘ tiver alguma dĂșvida, verifique Codex.

,

Leave a comment

How to Stop WordPress Editor From Removing Break Tags <p> and <br />

If you are experiencing problems with the <p> and <br /> tags on your WordPress site, if they are automatically being removed from your posts causing spacing issues, there’s a simple workaround to deal with it.
Se vocĂȘ estĂĄ enfrentando problemas com as tags <p> and <br /> no seu site WordPress, se elas estĂŁo sendo removidas automaticamente de seus posts causando dificuldades no espaçamento, hĂĄ um jeito simples de lidar com isso.

Download and install the WordPress Plugin TinyMCE Advanced. After that, go to Settings / TinyMCE Advanced / Advanced and check / click the options marked on the picture bellow. WordPress will not ignore anymore the break tags <p> and <br />.
Baixe e instale o Plugin WordPress TinyMCE Advanced. Depois disso, vå até ConfiguraçÔes / TinyMCE Advanced / Advanced e marque / clique as opçÔes assinaladas na figura abaixo. O WordPress não vai mais ignorar as tags de quebra <p> and <br />.

Hope you find this tip useful 😉
Espero que vocĂȘ ache esta dica Ăștil 😉

,

Leave a comment

%d bloggers like this: