How to designate category link in title according to widget
-
Peace all,
Currently on my theme, when it displays the widget blocks it will give the widget title and the corresponding articles related to the category, but the title does not link to the category at all. How can I make this possible?
For example, I want the “Just Living” title to link to the “Just Living” category, so this way my readers don’t have to scroll all the way up to the navbar
Here’s what the coding for the Widget.php looks like
[ Moderator Note: Please post code or markup snippets between backticks or use the code button and not blockquote. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser. ]
<?php add_action('widgets_init', 'pyre_homepage_2col_load_widgets'); function pyre_homepage_2col_load_widgets() { register_widget('Pyre_Homepage_2col_Widget'); } class Pyre_Homepage_2col_Widget extends WP_Widget { function Pyre_Homepage_2col_Widget() { $widget_ops = array('classname' => 'pyre_homepage_2col', 'description' => 'Homepage 2-column recent posts widget.'); $control_ops = array('id_base' => 'pyre_homepage_2col-widget'); $this->WP_Widget('pyre_homepage_2col-widget', 'Avenue Theme: Home 2-column', $widget_ops, $control_ops); } function widget($args, $instance) { extract($args); $show_excerpt = isset($instance['show_excerpt']) ? 'true' : 'false'; $title = $instance['title']; $post_type = 'all'; $categories = $instance['categories']; $posts = $instance['posts']; $images = true; $title_2 = $instance['title_2']; $post_type_2 = 'all'; $categories_2 = $instance['categories_2']; $posts_2 = $instance['posts_2']; $images_2 = true; echo $before_widget; ?> <?php $post_types = get_post_types(); unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']); if($post_type == 'all') { $post_type_array = $post_types; } else { $post_type_array = $post_type; } ?> <div class="block half"> <h3><?php echo $title; ?> <span class="arrows">?</span></h3> <?php $recent_posts = new WP_Query(array( 'showposts' => $posts, 'post_type' => $post_type_array, 'cat' => $categories, )); ?> <?php $counter = 1; while($recent_posts->have_posts()): $recent_posts->the_post(); ?> <?php if(has_post_format('video') || has_post_format('audio') || has_post_format('gallery')) { $icon = '<span class="' . get_post_format($post->ID) . '-icon"></span>'; } else { $icon = ''; } ?> <?php if($counter == 1): ?> <div class="block-item-big"> <?php if($images && has_post_thumbnail()): ?> <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image'); ?> <div class="block-image"><a>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div> <?php else: ?> <div class="block-image"><a>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=290&h=160" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div> <?php endif; ?> <h2><a>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2> <span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span> <?php if($show_excerpt == 'true'): ?><p><?php echo string_limit_words(get_the_excerpt(), 15); ?> ...</p><?php endif; ?> </div> <?php else: ?> <div class="block-item-small"> <?php if($images && has_post_thumbnail()): ?> <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image-thumb'); ?> <div class="block-image"><a>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='50' height='50' /></a><?php echo $icon; ?></div> <?php else: ?> <div class="block-image"><a>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=60&h=60" alt="<?php the_title(); ?>" width='50' height='50' /></a><?php echo $icon; ?></div> <?php endif; ?> <h2><a>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2> <span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span> </div> <?php endif; ?> <?php $counter++; endwhile; ?> </div> <?php $post_types = get_post_types(); unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']); if($post_type_2 == 'all') { $post_type_2_array = $post_types; } else { $post_type_2_array = $post_type; } ?> <div class="block half last"> <h3><?php echo $title_2; ?> <span class="arrows">?</span></h3> <?php $recent_posts = new WP_Query(array( 'showposts' => $posts_2, 'post_type' => $post_type_2_array, 'cat' => $categories_2, )); ?> <?php $counter = 1; while($recent_posts->have_posts()): $recent_posts->the_post(); ?> <?php if(has_post_format('video') || has_post_format('audio') || has_post_format('gallery')) { $icon = '<span class="' . get_post_format($post->ID) . '-icon"></span>'; } else { $icon = ''; } ?> <?php if($counter == 1): ?> <div class="block-item-big"> <?php if($images && has_post_thumbnail()): ?> <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image'); ?> <div class="block-image"><a>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div> <?php else: ?> <div class="block-image"><a>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=290&h=160" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div> <?php endif; ?> <h2><a>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2> <span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span> <?php if($show_excerpt == 'true'): ?><p><?php echo string_limit_words(get_the_excerpt(), 15); ?> ...</p><?php endif; ?> </div> <?php else: ?> <div class="block-item-small"> <?php if($images && has_post_thumbnail()): ?> <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image-thumb'); ?> <div class="block-image"><a>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='50' height='50' /></a><?php echo $icon; ?></div> <?php else: ?> <div class="block-image"><a>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=60&h=60" alt="<?php the_title(); ?>" width='50' height='50' /></a><?php echo $icon; ?></div> <?php endif; ?> <h2><a>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2> <span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span> </div> <?php endif; ?> <?php $counter++; endwhile; ?> </div> <?php echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['show_excerpt'] = $new_instance['show_excerpt']; $instance['title'] = $new_instance['title']; $instance['post_type'] = 'all'; $instance['categories'] = $new_instance['categories']; $instance['posts'] = $new_instance['posts']; $instance['show_images'] = true; $instance['title_2'] = $new_instance['title_2']; $instance['post_type_2'] = 'all'; $instance['categories_2'] = $new_instance['categories_2']; $instance['posts_2'] = $new_instance['posts_2']; $instance['show_images_2'] = true; return $instance; } function form($instance) { $defaults = array('show_excerpt' => null, 'title' => 'Recent Posts', 'post_type' => 'all', 'categories' => 'all', 'posts' => 4, 'title_2' => 'Recent Posts', 'post_type_2' => 'all', 'categories_2' => 'all', 'posts_2' => 4); $instance = wp_parse_args((array) $instance, $defaults); ?> <p> <input class="checkbox" type="checkbox" <?php checked($instance['show_excerpt'], 'on'); ?> id="<?php echo $this->get_field_id('show_excerpt'); ?>" name="<?php echo $this->get_field_name('show_excerpt'); ?>" /> <label for="<?php echo $this->get_field_id('show_excerpt'); ?>">Show excerpt</label> </p> <h3>Column One</h3> <p> <label for="<?php echo $this->get_field_id('title'); ?>">Title:</label> <input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" /> </p> <p> <label for="<?php echo $this->get_field_id('categories'); ?>">Filter by Category:</label> <select id="<?php echo $this->get_field_id('categories'); ?>" name="<?php echo $this->get_field_name('categories'); ?>" class="widefat categories" style="width:100%;"> <option value='all' <?php if ('all' == $instance['categories']) echo 'selected="selected"'; ?>>all categories</option> <?php $categories = get_categories('hide_empty=0&depth=1&type=post'); ?> <?php foreach($categories as $category) { ?> <option value='<?php echo $category->term_id; ?>' <?php if ($category->term_id == $instance['categories']) echo 'selected="selected"'; ?>><?php echo $category->cat_name; ?></option> <?php } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('posts'); ?>">Number of posts:</label> <input class="widefat" style="width: 30px;" id="<?php echo $this->get_field_id('posts'); ?>" name="<?php echo $this->get_field_name('posts'); ?>" value="<?php echo $instance['posts']; ?>" /> </p> <h3 style='margin-top: 40px;'>Column Two</h3> <p> <label for="<?php echo $this->get_field_id('title_2'); ?>">Title:</label> <input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('title_2'); ?>" name="<?php echo $this->get_field_name('title_2'); ?>" value="<?php echo $instance['title_2']; ?>" /> </p> <p> <label for="<?php echo $this->get_field_id('categories_2'); ?>">Filter by Category:</label> <select id="<?php echo $this->get_field_id('categories_2'); ?>" name="<?php echo $this->get_field_name('categories_2'); ?>" class="widefat categories" style="width:100%;"> <option value='all' <?php if ('all' == $instance['categories_2']) echo 'selected="selected"'; ?>>all categories</option> <?php $categories = get_categories('hide_empty=0&depth=1&type=post'); ?> <?php foreach($categories as $category) { ?> <option value='<?php echo $category->term_id; ?>' <?php if ($category->term_id == $instance['categories_2']) echo 'selected="selected"'; ?>><?php echo $category->cat_name; ?></option> <?php } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('posts_2'); ?>">Number of posts:</label> <input class="widefat" style="width: 30px;" id="<?php echo $this->get_field_id('posts_2'); ?>" name="<?php echo $this->get_field_name('posts_2'); ?>" value="<?php echo $instance['posts_2']; ?>" /> </p> <?php } } ?>
- The topic ‘How to designate category link in title according to widget’ is closed to new replies.