WordPress.org

Ready to get started?Download WordPress

Forums

Show portfolio-categorie in sidebar (9 posts)

  1. jpdeboer
    Member
    Posted 3 years ago #

    In this theme I have a sidebarwidget, that shows news from newscategories I can fill in. Now I want the same, but then for portfolio-categories.

    I found this permanent solution:

    Open up sidebar_news.php and find this line:
    $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);

    Change it to:

    $additional_loop = new WP_Query("post_type=portfolio&cat=".$cat."&posts_per_page=".$count);

    Unfortunately this is a permanent solution and I am looking to make both possible.

    This was said:

    If you want to use the Sidebar News widget for the blog entries and for the portfolio entries you need to duplicate the widget or change it's code (more complex). I would create an extra portfolio news widget based on "Sidebar News" widget. Currently it's not possible to show both post types.

    Now I tried duplicating the widget and change things so I see it in the widget area, but no luck.

    Anybody any idea how to get a copy of this news-widget?

  2. jpdeboer
    Member
    Posted 3 years ago #

    Anybody who can help me with this?
    Please?

  3. kapilj
    Member
    Posted 3 years ago #

    If you are using any specific theme, please let me know which one are you usgin.

    Normally widgets are defined in the function file. Try to search for the news widget. To make is duplicate copy the code and replace news with portfolio in the copied text.

    Also I think you have to create a copy of "sidebar_news.php" page as "Sidebar_portfolio.php" and make edits into it.

    Hope this works for you.

    Thanks!
    Kapil

  4. jpdeboer
    Member
    Posted 3 years ago #

    Hello Kapil,

    Thanks for your reply!
    I'm using the Avisio theme and already tried what you wrote. But I still see only one widget in the Dashboard and not two.

    I made a copy of sidebar_news.php as sidebar_portfolio.php and changed all news to portfolio. This is the new code:

    <?php
    /* Add our function to the widgets_init hook. */
    add_action( 'widgets_init', 'kriesi_sidebar_portfolio_widget' );
    
    /* Function that registers our widget. */
    function kriesi_sidebar_portfolio_widget() {
    	global $kriesiaddwidget;
    	$kriesiaddwidget = 0;
    	register_widget( 'Kriesi_sidebar_portfolio_Widget' );
    }
    
    class Kriesi_sidebar_portfolio_Widget extends WP_Widget {
    	function Kriesi_sidebar_portfolio_Widget()
    	{
    		$widget_ops = array('classname' => 'community_portfolio', 'description' => 'A Sidebar widget to display posts in your sidebar' );
    
    		$this->WP_Widget( 'community_portfolio', THEMENAME.' Sidebar Portfolio', $widget_ops );
    	}
    
    	function widget($args, $instance)
    	{
    		global $k_option;
    		extract($args, EXTR_SKIP);
    		echo $before_widget;
    
    		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
    		$count = empty($instance['count']) ? '' : apply_filters('widget_entry_title', $instance['count']);
    		$cat = empty($instance['cat']) ? '' : apply_filters('widget_comments_title', $instance['cat']);
    
    		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
    
    		$additional_loop = new WP_Query("post_type=portfolio&cat=".$cat."&posts_per_page=".$count);
    		if($additional_loop->have_posts()) :
    		while ($additional_loop->have_posts()) : $additional_loop->the_post();
    
    		global $post;
    		$small_prev = kriesi_post_thumb($post->ID, array('size'=> array('S'),
    															'display_link' => array('permalink'),
    															'wh' => $k_option['custom']['imgSize']['S'],
    															'img_attr' => array('class'=>'rounded_small ie6fix alignleft'),
    															'link_attr' => array('class'=>'alignleft  preloading_background')
    															));
    		?>
    
    			<div class="entry box_entry">
    			<h4><a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php _e('Permanent Link:','avisio')?><?php the_title(); ?>"><?php the_title(); ?></a></h4>
    
    			<?php
    			if($small_prev) echo $small_prev;
    			the_excerpt('Read more'); ?>
    			</div>
    
    		<?php
    		endwhile;
    		endif;
    
    		echo $after_widget;
    
    	}
    
    	function update($new_instance, $old_instance)
    	{
    		$instance = $old_instance;
    		$instance['title'] = strip_tags($new_instance['title']);
    		$instance['count'] = strip_tags($new_instance['count']);
    		$instance['cat'] = strip_tags($new_instance['cat']);
    		return $instance;
    	}
    
    	function form($instance)
    	{
    		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => '', 'cat' => '' ) );
    		$title = strip_tags($instance['title']);
    		$count = strip_tags($instance['count']);
    		$cat = strip_tags($instance['cat']);
    ?>
    		<p><label for="<?php echo $this->get_field_id('title'); ?>">Title:
    		<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
    
    		<p><label for="<?php echo $this->get_field_id('count'); ?>">How many entries do you want to display:
    		<input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo attribute_escape($count); ?>" /></label></p>
    
    		<p><label for="<?php echo $this->get_field_id('cat'); ?>">Enter the ids of the categories you want to display, separate them by comma:
    		<input class="widefat" id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>" type="text" value="<?php echo attribute_escape($cat); ?>" /></label></p>
    
    <?php
    	}
    }

    In functions.php I found this line
    $autoload['widgets'] = array('sidebar_news');
    and copied it underneath it like this
    $autoload['widgets'] = array('sidebar_portfolio');

    Still nothing.

    Any ideas? What am I doing wrong?

  5. kapilj
    Member
    Posted 3 years ago #

    As "Avisio theme" is a premium theme on themeforest.net, it is difficult to find out the solution.

    It is possible for you to share the theme or setup a demo site and share the login credentials.

    Thanks!
    Kapil

  6. jpdeboer
    Member
    Posted 3 years ago #

    @Kapil
    Does this help?
    SELECT SQL_CALC_FOUND_ROWS wp_blog1posts.* FROM wp_blog1posts INNER JOIN wp_blog1term_relationships ON (wp_blog1posts.ID = wp_blog1term_relationships.object_id) INNER JOIN wp_blog1term_taxonomy ON (wp_blog1term_relationships.term_taxonomy_id = wp_blog1term_taxonomy.term_taxonomy_id) WHERE 1=1 AND wp_blog1term_taxonomy.taxonomy = 'category' AND wp_blog1term_taxonomy.term_id IN ('102') AND wp_blog1posts.post_type = 'portfolio' AND (wp_blog1posts.post_status = 'publish' OR wp_blog1posts.post_status = 'private') GROUP BY wp_blog1posts.ID ORDER BY wp_blog1posts.post_date DESC LIMIT 0, 4

  7. jpdeboer
    Member
    Posted 3 years ago #

    This is the complete error:

    WP_Query Object
    (
        [query_vars] => Array
            (
                [taxonomy] => portfolio_entries
                [post_type] => portfolio
                [cat] => 102
                [posts_per_page] => 4
                [error] =>
                [m] => 0
                [p] => 0
                [post_parent] =>
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [name] =>
                [static] =>
                [pagename] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [hour] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] =>
                [tag] =>
                [tag_id] => 0
                [author_name] =>
                [feed] =>
                [tb] =>
                [paged] => 0
                [comments_popup] =>
                [meta_key] =>
                [meta_value] =>
                [preview] =>
                [s] =>
                [sentence] =>
                [category__in] => Array
                    (
                        [0] => 102
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
                [caller_get_posts] =>
                [suppress_filters] =>
                [cache_results] => 1
                [update_post_term_cache] => 1
                [update_post_meta_cache] => 1
                [nopaging] =>
                [comments_per_page] => 50
                [no_found_rows] =>
                [order] => DESC
                [orderby] => wp_blog1posts.post_date DESC
            )
    
        [request] =>  SELECT SQL_CALC_FOUND_ROWS  wp_blog1posts.* FROM wp_blog1posts  INNER JOIN wp_blog1term_relationships ON (wp_blog1posts.ID = wp_blog1term_relationships.object_id) INNER JOIN wp_blog1term_taxonomy ON (wp_blog1term_relationships.term_taxonomy_id = wp_blog1term_taxonomy.term_taxonomy_id)  WHERE 1=1  AND wp_blog1term_taxonomy.taxonomy = 'category'  AND wp_blog1term_taxonomy.term_id IN ('102')  AND wp_blog1posts.post_type = 'portfolio' AND (wp_blog1posts.post_status = 'publish' OR wp_blog1posts.post_status = 'private') GROUP BY wp_blog1posts.ID ORDER BY wp_blog1posts.post_date DESC LIMIT 0, 4
        [post_count] => 0
        [current_post] => -1
        [in_the_loop] =>
        [post] =>
        [comments] =>
        [comment_count] => 0
        [current_comment] => -1
        [comment] =>
        [found_posts] => 0
        [max_num_pages] => 0
        [max_num_comment_pages] => 0
        [is_single] =>
        [is_preview] =>
        [is_page] =>
        [is_archive] => 1
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] => 1
        [is_tag] =>
        [is_tax] =>
        [is_search] =>
        [is_feed] =>
        [is_comment_feed] =>
        [is_trackback] =>
        [is_home] =>
        [is_404] =>
        [is_comments_popup] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] =>
        [is_robots] =>
        [is_posts_page] =>
        [is_paged] =>
        [query] => taxonomy=portfolio_entries&post_type=portfolio&cat=102&posts_per_page=4
        [posts] => Array
            (
            )
    
    )
  8. jpdeboer
    Member
    Posted 3 years ago #

    Ok, almost got it working now, but still one problem. Sidebar-widget now shows all posts in portfolio when category-numbers are not filled in in widget. So that's ok. But when I fill in a category-number it doesn't show anything. Looks like it does not look at a categorynumber at all.
    Any idea what is wrong?

  9. jpdeboer
    Member
    Posted 3 years ago #

    Anybody?
    Please????

Topic Closed

This topic has been closed to new replies.

About this Topic