• Resolved nadimtheadmin

    (@nadimtheadmin)


    I needed the category name to be displayed on the top of the sidebar so i tried creating a widget:

    <?php
    /*
    Plugin Name: DisplayCategoryName
    Description: Category Name
    Author: Nadim Lahoud
    Version: 0.001
    Author URI: none
    */
    function get_cat_name($args) {
        extract($args);
    ?>
            <?php echo $before_widget; ?>
               <?php /* If this is a category archive */ } elseif (is_category()) { ?>
    			<h3><p><?php single_cat_title(''); ?></p></h3>
            <?php echo $after_widget; ?>
    <?php
    }
    register_sidebar_widget('GetCateName',
        'widget_getcatname');

    It says error on line 13.

    I know this is very specific but this is my first widget/plugin and help would be greatly appreciated.
    What’s wrong with line 13?
    Are there any other mistakes I made?
    Is there an easier way to achieve the desired result?

    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • I would not have thought a plugin would be needed for that.

    Thread Starter nadimtheadmin

    (@nadimtheadmin)

    The thing is that when I widgetised my Contempt theme it stopped displaying the name of the category pages on the top of the sidebar.
    When I looked into the theme’s old sidebar.php file I found part of the code you see above and tried to implement it into a widget for my new customisable sidebar. But I just cant seem to get it right without any help.

    You need to edit the widget parameters in functions.php (for the theme).

    Thread Starter nadimtheadmin

    (@nadimtheadmin)

    ok this is the theme’s functions.php:
    `<?php
    if ( function_exists(‘register_sidebar’) )
    register_sidebar(array(
    ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
    ‘after_widget’ => ‘
    ‘,
    ‘before_title’ => ”,
    ‘after_title’ => ”,
    ));

    ?>
    `

    Can you help me edit it? (I don’t really know what to do :))

    Thanks a million.

    I could be wrong, but this doesn’t looke right to me

    ‘after_title’ => ”,
    ));

    I doubt you’d have a comma before a closing bracket. You either need somthing after that comma, or to remove it.

    There are some good examples in the Codex. You are right on track.

    Thread Starter nadimtheadmin

    (@nadimtheadmin)

    @root
    hey i didn’t write this! This is how it came! (After the widgetizing)
    This works perfectly but I really need to have the Title of the category either first thing on the page or in the sidebar (as it was before). I’m a complete newbie when it comes to php and I somehow managed to get a few things done but this is over my head…

    @mrmist
    Thanks, removed the comma but I dont think it was doing anything wrong. It was just unnecessary.

    I may have misunderstood the question.

    Thread Starter nadimtheadmin

    (@nadimtheadmin)

    OK, no prob I’ll explain again. I’m using this them called Contempt. The theme used to display the name of the category first thing in the sidebar when you were in a category page. When I widgetized the theme, the new sidebar didn’t have this function. So I thought that the quickest way to add it would be by creating a widget and place it at the top of the sidebar.

    Maybe there’s a better way?

    Thread Starter nadimtheadmin

    (@nadimtheadmin)

    Found it!

    I just added <p><h3> -<?php single_cat_title(); ?></h3></p> before The Loop in my theme’s index.php.

    Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Help Needed for Plugin Development’ is closed to new replies.