Show subcategories and hide posts or show posts if not exists subcategories

I would use a combination of get_categories and get_category_children to achieve this. For example: On the home page include something like this: <?php $args=array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ); $categories=get_categories($args); foreach($categories as $category) { $catChildren = get_term_by($category->ID, ‘category’); if(!empty($catChildren)) { echo ‘<h3><a href=www.yourwebsite.com/”‘ . $category->slug . ‘”>’ . $category->name . ‘</h3>’; } } … Read more

Add Category Descriptions to Montezuma Theme

The WordPress template hierarchy indicates that index.php is the template used, if category.php and archive.php are missing. So, you can insert your code in index.php, and wrap it in a is_category conditional to make sure it’s only executed when a category archive is being displayed: <?php if( is_category() ) { // category description } ?>

Trying to WP_Query a category

You are using WP_Query incorrectly: you need to be calling the have_posts() and the_post() functions as methods of your $query variable: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> Becomes: <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?> You should also call wp_reset_postdata(); after the query loop is finished. … Read more

One color to category link depending on category ID

Open the page which is rendering the category posts, and in the appropriate place (before running the loop) write the following code <?php $catid = get_cat_id(); $color = “#222”; //default; if ($catid == $pinkCategoryId) $color = “#8B0A50”; else if ($catid == $redCategoryId) $color = “#FF0000″; ?> <style type=”text/css”> a { color: <?php echo $color;?>; } … Read more

Link to page in category

After a long search on the Web, I decided to take a look at the plugins @anjum sent, and found out this can be done through: <a href=”https://wordpress.stackexchange.com/questions/110906/<?php get_pagenum_link($i); ?>”>Link to page $i</a>

Print child category slug nicename

seems nobody understood ‘my question’, so I solved it myself here is the code for getting the slug I needed <?php $cat = get_term_by(‘name’, single_cat_title(”,false), ‘category’); echo $cat->slug; ?>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)