How to set widget only on front page?

ClassiBase classifieds script Forums General help How to set widget only on front page?

This topic contains 5 replies, has 3 voices, and was last updated by  infoactivo 1 year, 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2435 Reply

    Dmitry Grunt
    Participant

    Trying to show home page description only on HOME, but it shows on all main categories. What is wrong?

    <?php
    if($page_type == IndexController::PAGE_TYPE_HOME){
    echo "home";
    }
    ?>
    #2437 Reply

    infoactivo
    Participant

    In some way you’ll have to test if it is the index page.
    Find function index() in the IndexController.php and you’ll see where the title for the index page is set. I’ve made changes in the IndexController.php file itself, not in any widget, but I would like to know of any solution you came across.

    #2438 Reply

    Dmitry Grunt
    Participant

    Thank you for reply.

    I find that all root locations is HOME_PAGE. I don’t know why developers did it, usually web sites have only one Home page.
    Maybe this script have something like function “is_frontpage()” in WordPress?

    function index()
    {
    // get location if not set
    if(!self::$selected_location)
    {
    self::$selected_location = Config::getDefaultLocation();
    }

    // build breadcrumb
    $this->_buildBreadcrumb(self::$selected_location, self::$selected_category);

    // title for index
    $title = Config::option(‘site_title’);
    if(self::$selected_location)
    {
    $title = Location::getFullName(self::$selected_location, ”, ‘, ‘, true) . ‘ – ‘ . $title;
    $page_description = Location::getDescription(self::$selected_location);
    if($page_description)
    {
    $this->setMeta(‘description’, View::escape(TextTransform::excerpt($page_description, 155)));
    }
    }
    $this->setMeta(‘title’, $title);

    $vars = array(
    ‘page_type’ => self::PAGE_TYPE_HOME,
    ‘selected_location’ => self::$selected_location,
    ‘selected_category’ => self::$selected_category,
    ‘catfield’ => CategoryFieldRelation::getCatfields(self::$selected_location->id, self::$selected_category->id, true, true),
    ‘page_description’ => $page_description,
    ‘page_title’ => ”
    );

    // load widgets to locations
    Widget::render($vars);

    // canonical link
    $url_origin = Location::urlOrigin(self::$selected_location, self::$selected_category);
    $header_other = ‘<link rel=”canonical” href=”‘ . Location::url(self::$selected_location, self::$selected_category) . ‘” />’;
    $header_other .= Language::relAlternate($url_origin);

    // custom rss
    if(strlen($url_origin))
    {
    $header_other .= Config::formatRssLink(array(‘location’ => self::$selected_location));
    $header_other .= Config::formatRssLink(array(‘type’ => ‘featured’, ‘location’ => self::$selected_location));
    }

    $this->setMeta(‘header_other’, $header_other);

    // define language switch
    Language::htmlLanguageBuild($url_origin);

    $this->display(‘index/index’, $vars);
    }

    #2441 Reply

    ClassiBase
    Keymaster

    Yes you are right, any location page is considered as home page. It is like a home page for that location. If you want to detect if it is home page where no location is set then you can check it with selected location. If you are adding code to index controller then you can do it like this:

    if(!self::$selected_location)
    {
     // this is home page without any location
    }

    If you are calling it inside a widget then you can use it like this:

    if(is_null(self::$_vars['selected_location']))
    {
     // this is home page without any location
    }
    #2442 Reply

    Dmitry Grunt
    Participant

    Thank you for help!
    I used second code in widget it works as needed – text shows only on front page.

    #2444 Reply

    infoactivo
    Participant

    great to know how to use it in widgets.
    a little difference that makes all difference…

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: How to set widget only on front page?
Your information: