WordPress.org

Forums

[resolved] Help Needed for Plugin Development (11 posts)

  1. nadimtheadmin
    Member
    Posted 7 years ago #

    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!

  2. Root
    Member
    Posted 7 years ago #

    I would not have thought a plugin would be needed for that.

  3. nadimtheadmin
    Member
    Posted 7 years ago #

    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.

  4. Root
    Member
    Posted 7 years ago #

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

  5. nadimtheadmin
    Member
    Posted 7 years ago #

    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' => '

  6. ',
    'before_title' => '',
    'after_title' => '',
    ));

    ?>
    `

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

    Thanks a million.

  • mrmist
    Forum Janitor
    Posted 7 years ago #

    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.

  • Root
    Member
    Posted 7 years ago #

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

  • nadimtheadmin
    Member
    Posted 7 years ago #

    @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.

  • Root
    Member
    Posted 7 years ago #

    I may have misunderstood the question.

  • nadimtheadmin
    Member
    Posted 7 years ago #

    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?

  • nadimtheadmin
    Member
    Posted 7 years ago #

    Found it!

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

    Thanks.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags