WordPress.org

Ready to get started?Download WordPress

Forums

Implementing a widget plugin to PHP (5 posts)

  1. mikhuebner
    Member
    Posted 1 year ago #

    I am trying to implement a widget called 'Widgetize pages' to display categories of different posts on the main page which I am not running static. I need a little help on coding this out in PHP. Here is the link to the site, you can kind of get the idea of what I am doing through this.

    http://www.southwestshadow.com/

    Any help at all is appreciated. Thanks guys.

  2. rajeishkumarngn1
    Member
    Posted 1 year ago #

    A Toronto based Toronto Wedding Limo service provider. Contact for Limo Services in Toronto Limo Rentals, Mississauga, Brampton, Richmond Hill, Oakville, Markham, Scarborough, Milton and George Town.

  3. samateo
    Member
    Posted 1 year ago #

    I've used widgets and Mini-Loops to do something similar.

    To make this work, your theme would need to be widgetized with an area to drop in x mini-loop widgets that pull posts according to the criteria you set.

    Tag the posts you create as 'news', 'featured', 'opinion', 'a&e', etc. Next, drop a mini-loops widget into the section of your theme where you want the specific group of posts to appear. Last, set the criteria for each widget to show just that group.

    ** Put any modifications to your theme in a child theme if you're concerned about changes being overwritten.

  4. mikhuebner
    Member
    Posted 1 year ago #

    But how do I get this to display on the main index.php? I am lost on how to do this because nothing I do seems to work. Implementing a widget code didn't work so I need a PHP code that will allow me to do this.

  5. samateo
    Member
    Posted 1 year ago #

    in your functions.php, register a widget area with register_sidebar() called from 'widgets_init'

    function my_widget_area_init() {
    	register_sidebar( array(
    		'name' => 'Home Page Widget Area',
    		'id' => 'my_widget_post_area_id',
    		'before_widget' => '<div>',
    		'after_widget' => '</div>',
    		'before_title' => '<h2>',
    		'after_title' => '</h2>',
    	) );
    }
    add_action( 'widgets_init', 'my_widget_area_init' );

    Change the 'id' to whatever you want. This will create a widget area that shows up in admin | appearance | widgets. You can drop your mini-loops widget (or whatever widgets you want to add) into the new area created in your admin.

    Next, you need to tell the html to look for the widget area that matches the id and output any widgets you've assigned.

    In your index.php put this:

    if(!dynamic_sidebar('my_widget_post_area_id')) { echo 'nothing to see here'; }

    Any widgets you've added in admin will appear in the new area. So if you add four widgets that each look for a specific type of post e.g. 'news', 'featured', 'opinion', 'a&e', you can fill in the areas with posts that match what you currently have on your home page.

    Set 'before_widget', 'before_title', etc. or wrap the php in the if statement above in section, article, div or whatever html tags and attributes are appropriate for your site, and to give it the style you want. You've got similar options with mini-loops to set before item, add urls, etc.

    Might be easier to leave the widget styles empty and recreate your current div class="colart" in the widget itself under the mini-loops format area.

    ** To use shortcodes in your widgets, you'll need to have this in your functions.php if not already there add_filter('widget_text', 'do_shortcode');

Topic Closed

This topic has been closed to new replies.

About this Topic