• Hello,

    We have a website (www.prephoops.com) where content is published by our writers to a specific state. We would like to have specific sidebars for each state that is displayed depending on the state location of the post. For example, a Minnesota article would display a Minnesota sidebar, Iowa would display the Iowa sidebar, and so forth.

    We currently have sidebars that are specific to each state homepage and we are trying to replicate that functionality for posts rather than homepages.

    I was able to create the widget areas for the articles using the following code:

    foreach ($state_pages as $page)
    {
    // ARTICLE SIDEBAR
    register_sidebar(array(
    ‘name’ => __( $page->post_title . ‘ – Articles > Sidebar’, ‘prephoops’ ),
    ‘id’ => $page->post_name . ‘_article_sidebar’,
    ‘description’ => ”,
    ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
    ‘after_widget’ => ”,
    ‘before_title’ => ‘<h2 class=”widgettitle”>’,
    ‘after_title’ => ‘</h2>’,
    ));

    Now I’m having trouble getting the post to pull in the correct widget area depending on the state. So basically, each time an article is posted, the state is selected and from there the correct sidebar needs to be pulled in.

    If anyone has suggestions on how to make this work, it would be greatly appreciated. Thanks!

The topic ‘Calling multiple sidebars by state’ is closed to new replies.