Skip to:
Content
Pages
Categories
Search
Top
Bottom

Recent topics widget – how to add forum url to title


  • forwardslashdesigns
    Participant

    @forwardslashdesigns

    Hi,

    Title says it all really. I am trying to customise the recent topics widget; using it to display topics from a specific forum; and I would like the title to link to the forum from which the topics are from.

    I have registered a sidebar for this in my functions.php file and I’ve tried the following code, but it doesnt work as its not adding the URL into the title:

    register_sidebar(
    		array(
    			'id' => 'forumcontent',
    			'name' => __( 'Forum Home Content - Colleges', 'textdomain' ),
    			'description' => __( 'A short description of the sidebar.', 'textdomain' ),
    			'before_widget' => '<div id="%1$s" class="widget-topic-list %2$s">',
    			'after_widget' => '</div>',
    			'before_title' => '' . apply_filters( 'bbp_get_forum_permalink', get_permalink( $forum_id ) ) . '<h3 class="widget-title">',
    			'after_title' => '</h3><a/> <br class="clear"/>'
    		)
    	);

    I am trying to create something similar to this: http://postimg.org/image/55qwbgoe3/

    I am currently editing the the bbpress/includes/common/widgets.php file directly which I know is a BIG NO NO! and I should create a custom widget for this, but I am not really sure how to!

    I am currently using WordPress v3.6 and Bbpress v2.5.3

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

  • Robin W
    Moderator

    @robin-w

    ok, without me spending hours digging into this, let’s see if we can sort it.

    and yes you can cut the code into a functions file by renaming it, but we’ll fix that later.

    For the moment, where are you registering the new sidebar? In a main theme for a child theme?

    If in a child theme, they won’t register as sidebars have already been loaded. So you need to unload and reload them all in one go (no idea why, it’s just what I learnt when I tried to add a sidebar in my child theme.)

    so what my child theme functions file starts with is

    remove_action( 'widgets_init', 'twentyten_widgets_init' ); //necessary to replace parent theme's code which is a twentyten theme
    function twentytenchild_widgets_init() {
    	// Area 1, located at the top of the sidebar.
    	register_sidebar( array(
    		'name' => __( 'Primary Widget Area', 'twentytenchild' ),
    		'id' => 'primary-widget-area',
    		'description' => __( 'The primary widget area', 'twentytenchild' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );

    so it starts by removing the twentyten sidebar’s and then adds them straight back – my child theme for the twentyten main theme is excitingly called “twentytenchild”!. I have just shown the first widget from the parent theme, all are just copied from the parent theme. Several others follow
    Then on the end you add your new sidebar.

    Then after that you complete and register them viz :

    	//** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
    add_action( 'widgets_init', 'twentytenchild_widgets_init' );
    

    by the by in your after title you need to change the a/ to /a

    Give that a go, and come back if it works, and we’ll then talk about taking the widget into a custom one.


    forwardslashdesigns
    Participant

    @forwardslashdesigns

    Hi Robin, thanks for the quick reply.

    I am registering a new sidebar in the main theme. I am not using a child theme for this website.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar