Neuigkeiten
  • Die modified eCommerce Shopsoftware ist kostenlos, aber nicht umsonst.
    Spenden
  • Damit wir die modified eCommerce Shopsoftware auch zukünftig kostenlos anbieten können:
    Spenden
  • Thema: Php Link mit CSS formatieren

    jpx10

    • Frisch an Board
    • Beiträge: 78
    Php Link mit CSS formatieren
    am: 08. April 2013, 11:21:25
    Hallo zusammen

    Ich bin aktuell echt am verzeweifeln. Ich verwende für meine Kat Navigation ein Script, bei welchem auch externe Links eingebunden werden können. In der entsprechenden php Datei werden diese mit dem Aufruf

    Code: PHP  [Auswählen]
            $ct->addLink('Home', xtc_href_link('index.php'), 249, 0);

    eingebunden. Nun möchte ich eben diesen Link per CSS formatieren. Kann mir ein php Crack hier ein Tipp geben, wie ich hier z.B. eine Span Klasse oder dergleichen integriere? 

    Linkback: https://www.modified-shop.org/forum/index.php?topic=25685.0

    web0null

    • Experte
    • Beiträge: 1.998
    Re: Php Link mit CSS formatieren
    Antwort #1 am: 08. April 2013, 11:32:23
    Hi, schau dir doch die Function addLink mal an, da wird doch sicher ein Parameter für Attribute vorhanden sein, dem gibst du dann ein class="blabla" mit, das kannst du dann über css ansprechen.

    Gruß

    jpx10

    • Frisch an Board
    • Beiträge: 78
    Re: Php Link mit CSS formatieren
    Antwort #2 am: 08. April 2013, 11:48:11
    Herzlichen Dank für Deine Antwort

    Nun, ich bin noch etwas grün hinter den Ohren was php anbelangt. Die Function wird jedoch hier definiert. Wie genau müsste ich nun diese klasse integrieren?

    Code: PHP  [Auswählen]
    /**
             * addLink
             *
             * inserts a custom link into the category tree
             *
             */

            public function addLink($name, $link, $parent_id = 0, $position = 0)
            {
                    $level = 0;
                    $this->getLevel($this->categories, $level, $parent_id);
                    $parent_level = $level;

                    // if parent is not found in the current tree
                    if ($parent_level < 0) {
                            return false;
                    }

    web0null

    • Experte
    • Beiträge: 1.998
    Re: Php Link mit CSS formatieren
    Antwort #3 am: 08. April 2013, 13:56:36
    Zeig mal die ganze klasse, oder einen Download.

    Man könnte es auch noch mit a[href$="index.php"] ansprechen, müßte aber noch weiter gefiltert werden, über parent classen oder :not(...).

    Poste mal die html Ausgabe.

    jpx10

    • Frisch an Board
    • Beiträge: 78
    Re: Php Link mit CSS formatieren
    Antwort #4 am: 08. April 2013, 14:01:51
    Hier ist mal die gesamte categories.php.  Da ich ja gerne jeden Link einzeln per CSS angesteuert haben möchte, müsste ich die Klasse wohl im title verpacken. So könnte ich jeweils den Namen des Titels in der CSS aufrufen und so jeden Link separat ansteuern. Ist das überhaupt möglich?

    Code: PHP  [Auswählen]
    <?php

    /** ----------------------------------------------------------------------------
     *
     * categories.php
     *
     *
     * -----------------------------------------------------------------------------
     *
     * Released under the GNU General Public License
     *
     * @author Doc Olson (info@it-bites.de)
     *
     * ----------------------------------------------------------------------------- */

    class categories
    {

            protected $path = array();
            protected $cur_cat_id = 0;
            protected $categories = array();
            public $start_level = 0;
            public $min_level = 1;
            public $max_level = false;
            public $hide_empty = false;
            public $class_cur = 'current';
            public $class_active = 'active';
            public $class_cur_has_child = 'has_child';
            public $class_level = 'level_';
            public $class_cur_parent = 'current_parent';

            /**
             * __construct
             *
             */

            public function __construct($cPath, $cur_cat_id)
            {
                    $this->path = explode('_', $cPath);
                    $this->cur_cat_id = $cur_cat_id;
            }

            /**
             * addLink
             *
             * inserts a custom link into the category tree
             *
             *
             * @param string $name
             * @param string $link
             * @param integer $parent_id
             * @param integer $position
             */

            public function addLink($name, $link, $parent_id = 0, $position = 0)
            {
                    $level = 0;
                    $this->getLevel($this->categories, $level, $parent_id);
                    $parent_level = $level;

                    // if parent is not found in the current tree
                    if ($parent_level < 0) {
                            return false;
                    }

                    /*
                     * only add link, if it is...
                     * a. a child of the current category
                     * b. to be placed on a level that should be open initially (min_level)
                     */

                    if (
                            ($this->cur_cat_id != $parent_id && $parent_level + 1 >= $this->min_level) &&
                            $parent_id != 0
                    ) {
                            return false;
                    }

                    $cats = false;

                    if ($parent_id == 0) {
                            $cats = &$this->categories;
                    } else {
                            $cats = &$this->getBranch($this->categories, $parent_id);
                    }

                    if (!is_array($cats)) {
                            return false;
                    }

                    $c = count($cats);
                    if ($position >= $c) {
                            $position = $c;
                    }

                    for ($i = count($cats); $i > $position; $i--) {
                            $cats[$i] = $cats[$i - 1];
                    }

                    $cats[$position] = array(
                            'id' => false,
                            'parent' => $parent_id,
                            'level' => $parent_level + 1,
                            'title' => $name,
                            'link' => $link,
                            'current' => false
                    );
            }

            /**
             * getBranch
             *
             * returns a reference to the branch with the parent-id $parent
             *
             * @param array &$cats
             * @param integer $parent_id
             */

            protected function &getBranch(&$cats, $parent_id)
            {
                    $result = false;

                    for ($i = 0, $c = count($cats); $i < $c; $i++) {
                            if ($cats[$i]['id'] == $parent_id) {
                                    if (!is_array($cats[$i]['children'])) {
                                            $cats[$i]['children'] = array();
                                    }
                                    $result = & $cats[$i]['children'];
                            } else {
                                    if (is_array($cats[$i]['children']) && count($cats[$i]['children'])) {
                                            $result = & $this->getBranch($cats[$i]['children'], $parent_id);
                                    }
                            }

                            if (is_array($result)) {
                                    break;
                            }
                    }

                    return $result;
            }

            /**
             * determines on what level a category resides
             * if the category is not found, -1 will be returned
             *
             * @param array $cats
             * @param integer $cat_id
             * @param integer $level
             * @return integer
             */

            private function getLevel(&$cats, &$level, $cat_id)
            {
                    for ($i = 0, $c = count($cats); $i <= $c; $i++) {
                            if (isset($cats[$i]['children']) && count($cats[$i]['children'])) {
                                    $level++;
                                    $res = $this->getLevel($cats[$i]['children'], $level, $cat_id);
                                    if ($res !== false) {
                                            return $res;
                                    }
                            }

                            if ($cats[$i]['id'] == $cat_id) {
                                    return $level;
                            }
                    }
                    $level--;
                    return false;
            }

            /**
             * getCategories
             *
             */

            public function getCategories($cat_id = 0)
            {
                    $this->categories = array_merge($this->categories, $this->getSubCategories($cat_id));
            }

            /**
             * getSubCategories
             *
             * @param integer $cat_id
             * @param integer $level
             * @return array
             */

            protected function getSubCategories($cat_id = 0, $level = 1)
            {
                    $category = array();

                    $group_check = '';
                    if (GROUP_CHECK == 'true') {
                            $group_check = 'AND c.group_permission_' .
                                    $_SESSION['customers_status']['customers_status_id'] . ' = 1 ';
                    }

                    $res = xtc_db_query(
                            "-- categories.php template class
                SELECT c.categories_id, cd.categories_name
                FROM "
    . TABLE_CATEGORIES . " c
                INNER JOIN "
    . TABLE_CATEGORIES_DESCRIPTION . " cd
                ON c.categories_id = cd.categories_id
                WHERE
                    c.parent_id = $cat_id AND
                    c.categories_status = 1
                    $group_check AND
                    cd.language_id = "
    . (int)$_SESSION['languages_id'] . "
                ORDER BY c.sort_order, cd.categories_name"

                    );

                    while ($row = xtc_db_fetch_array($res, true)) {

                            $current = false;
                            $active = false;

                            if ($row['categories_id'] == $this->cur_cat_id) {
                                    $current = true;
                            }

                            if (in_array($row['categories_id'], $this->path)) {
                                    $active = true;
                                    $current = true;
                            }

                            $prd_count = $this->countProducts($row['categories_id'], false, false);

                            if (($prd_count > 0 && $this->hide_empty ) || !$this->hide_empty) {

                                    /*
                                      // if only one product is present, the link will go to
                                      // the product instead of the category
                                      if ($prd_count == 1) {

                                      $res2 = xtc_db_query("-- categories.php class
                                      SELECT p.products_id, pd.products_name
                                      FROM " . TABLE_PRODUCTS . " p
                                      JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                      ON p.products_id = pd.products_id
                                      JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc
                                      ON p.products_id = ptc.products_id
                                      WHERE ptc.categories_id = " . $row['categories_id'] . "
                                      AND pd.language_id = " . (int) $_SESSION['languages_id'] . "
                                      AND p.products_status = 1"
                                      );

                                      $row2 = xtc_db_fetch_array($res2, true);
                                      $link = xtc_href_link(
                                      FILENAME_PRODUCT_INFO,
                                      xtc_product_link(
                                      $row2['products_id'],
                                      $row2['products_name']
                                      )
                                      );
                                      } else {
                                      $link = xtc_href_link(
                                      FILENAME_DEFAULT,
                                      xtc_category_link($row['categories_id'], $row['categories_name'])
                                      );
                                      }
                                     */


                                    $link = xtc_href_link(
                                            FILENAME_DEFAULT,
                                            xtc_category_link($row['categories_id'], $row['categories_name'])
                                    );

                                    $title = htmlspecialchars(
                                            $row['categories_name'],
                                            ENT_COMPAT,
                                            CHARSET,
                                            false
                                    );

                                    $cat = array(
                                            'id' => $row['categories_id'],
                                            'parent' => $cat_id,
                                            'level' => $level,
                                            'title' => $title,
                                            'link' => $link,
                                            'current' => $current,
                                            'active' => $active
                                    );

                                    if (SHOW_COUNTS == 'true' || $this->hide_empty) {
                                            $cat['prd_count'] = $this->countProducts($row['categories_id']);
                                    }

                                    if (
                                            ( $level < $this->min_level || $active ) &&
                                            ( $level < $this->max_level || !$this->max_level )
                                    ) {
                                            $cat['children'] = $this->getSubCategories($row['categories_id'], $level + 1);
                                    }

                                    $category[] = $cat;
                            }
                    }

                    return $category;
            }

            /**
             * getMainCategory
             *
             * @return array
             */

            public function getMainCategory($mainId = NULL)
            {
                    $mainCategory = array();

        if ($mainId === NULL) {
          $mainId = (int)$this->path[0];
        }
                    if ($mainId == 0) {
                            $mainCategory = array(
                                    'title' => HEADER_TITLE_TOP,
                                    'link' => xtc_href_link(FILENAME_DEFAULT)
                            );
                    } else {

                            $group_check = NULL;
                            if (GROUP_CHECK == 'true') {
                                    $group_check = 'AND c.group_permission_' .
                                            $_SESSION['customers_status']['customers_status_id'] . ' = 1 ';
                            }

                            $res = xtc_db_query(
                                    "-- categories.php template class
                                    SELECT c.categories_id, cd.categories_name
                                    FROM "
    . TABLE_CATEGORIES . " c
                                    INNER JOIN "
    . TABLE_CATEGORIES_DESCRIPTION . " cd
                                    ON c.categories_id = cd.categories_id
                                    WHERE
                                            c.categories_id = $mainId AND
                                            c.categories_status = 1
                                            $group_check AND
                                            cd.language_id = "
    . (int)$_SESSION['languages_id'] . "
                                    ORDER BY c.sort_order, cd.categories_name"

                            );

                            while ($row = xtc_db_fetch_array($res, true)) {
                                    $link = xtc_href_link(
                                            FILENAME_DEFAULT,
                                            xtc_category_link($row['categories_id'], $row['categories_name'])
                                    );
                                    $title = htmlspecialchars(
                                            $row['categories_name'],
                                            ENT_COMPAT,
                                            CHARSET,
                                            false
                                    );
                                    $mainCategory = array(
                                            'title' => $title,
                                            'link' => $link
                                    );
                            }
                    }
                    return $mainCategory;
            }

            /**
             * getOutputHTML
             *
             * @param array $cats
             * @param integer $level
             * @return string
             */

            public function getOutputHTML($cats = false, $level = 0)
            {
                    if (!count($this->categories)) {
                            return null;
                    }

                    $cats = $cats ? $cats : $this->categories;

                    if ($level == 0) {
                            $result = sprintf('<ul class="%s">' . "\n", $this->class_level . $level);
                    } else {
                            $result = '';
                    }

                    foreach ($cats as $key => $cat) {
                            $classes = array();

                            if ($key == 0) {
                                    $classes[] = 'first';
                            }

                            if (($key + 1) == count($cats)) {
                                    $classes[] = 'last';
                            }

                            if ($cat['active']) {
                                    $classes[] = $this->class_active;
                            }

                            if ($cat['current']) {
                                    $classes[] = $this->class_cur;

                                    if (count($cat['children']) > 0) {
                                            $classes[] = $this->class_cur_has_child;
                                    }
                            }

                            $prd_count = SHOW_COUNTS == 'true' ? ' (<em>' . $cat['prd_count'] . '</em>)' : '';
                            if (isset($cat['children']) and !empty($cat['children'])) {
                                    $children = sprintf('<ul class="%s">' . "\n", $this->class_level . ($level + 1));
                                    $children .= $this->getOutputHTML($cat['children'], $cat['level']);
                                    $children .= "</ul>\n";
                            } else {
                                    $children = '';
                            }

                            $classes = count($classes) ? ' class="' . implode(' ', $classes) . '"' : '';

                            $result .= sprintf(
                                    '<li%s><a href="%s" title="%s"%s>%s%s</a>%s</li>',
                                    $classes, $cat['link'], $cat['title'], $classes, $cat['title'], $prd_count, $children
                            ) . "\n";
                    }

                    if ($level == 0) {
                            $result .= "</ul>\n";
                    }
                    return $result;
            }

            /**
             * getOutput
             *
             * @param array $cats
             * @param integer $level
             */

            public function getOutput($cats = false, $level = 0)
            {
                    return $this->categories;
            }

            /**
             * countProducts
             *
             * @param integer $cat_id
             * @param boolean $include_inactive
             * @return integer
             */

            public function countProducts($cat_id, $include_inactive = false)
            {
                    $count = 0;

                    if ($include_inactive) {
                            $active = '';
                    } else {
                            $active = "AND p.products_status = '1'";
                    }

                    $res = xtc_db_query(
                            "SELECT count(*) AS total
                FROM "
    . TABLE_PRODUCTS . " p
                INNER JOIN "
    . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
                ON p.products_id = p2c.products_id
                WHERE p2c.categories_id = $cat_id
                $active
                AND (
                    p.products_date_expire > NOW() OR
                                    p.products_date_expire IS NULL OR
                                    p.products_date_expire = '0000-00-00 00:00:00'
                            )"

                    );

                    $res = xtc_db_fetch_array($res, true);
                    $count += $res['total'];

                    $res = xtc_db_query("SELECT categories_id FROM " . TABLE_CATEGORIES . " WHERE parent_id = $cat_id");

                    if (xtc_db_num_rows($res, true)) {
                            while ($row = xtc_db_fetch_array($res, true)) {
                                    $count += $this->countProducts($row['categories_id'], $include_inactive);
                            }
                    }

                    return $count;
            }
    }

    web0null

    • Experte
    • Beiträge: 1.998
    Re: Php Link mit CSS formatieren
    Antwort #5 am: 08. April 2013, 14:20:18
    Nimm mal die Datei, und schreibe
    Code: PHP  [Auswählen]
    $ct->addLink('Home', xtc_href_link('index.php'), 249, 0, 'deineClass');

    WARTE: FEHLER

    Suche $classes[] = $class; in Zeile 401 und ersetze es mit $classes[] = $cat['class'];
    Oder lade die Datei nochmal, habe sie ausgewechselt.

    jpx10

    • Frisch an Board
    • Beiträge: 78
    Re: Php Link mit CSS formatieren
    Antwort #6 am: 08. April 2013, 14:43:47
    Herzlichen Dank, doch leider lässt sich der Link nach wie vor nicht ansteuern. Ich habe deineClass durch ExtLink ersetzt und rufe diese in der CSS auf. Doch da wird nichts geändert. Muss ich möglicherweise die jeweilige CSS noch irgendwo einbinden?

    Ich muss jetzt dann leider kurz weg und schau mir das sonst am Abend nochmals in Ruhe an. Ich danke Dir aber schon mal herzlich für Deine Hilfe.  :-)

    web0null

    • Experte
    • Beiträge: 1.998
    Re: Php Link mit CSS formatieren
    Antwort #7 am: 08. April 2013, 15:18:52
    Hast du die Datei nochmal geladen, damit der Fehler behoben ist?
    Dann probier mal
    Code: CSS  [Auswählen]
    a.ExtLink {
      color:#FF0000 !important;
    }
     

    jpx10

    • Frisch an Board
    • Beiträge: 78
    Re: Php Link mit CSS formatieren
    Antwort #8 am: 08. April 2013, 18:18:47
    Hallo web0null

    Ich habe die neue Datei nochmals hochgeladen und die css Anweisung wie von Dir beschrieben erfasst. Trotzdem bleibt alles beim alten. Hast Du eventuell noch etwas in der categories.php übersehen?

    Matt

    • Experte
    • Beiträge: 4.241
    Re: Php Link mit CSS formatieren
    Antwort #9 am: 08. April 2013, 19:02:54
    Ich gehe stark davon aus, dass es sich nicht um die Website in deinem Profil dreht, daher die Frage: Link?

    Modulfux

    • Experte
    • Beiträge: 3.590
    • Geschlecht:
    Re: Php Link mit CSS formatieren
    Antwort #10 am: 08. April 2013, 20:15:45
    Wieso fragst du denn nicht im webs-Forum? So wie es aussieht ist doch die Datei aus dem webs-Shop.

    Gruß
    Ronny

    noRiddle (revilonetz)

    • Experte
    • Beiträge: 13.988
    • Geschlecht:
    Re: Php Link mit CSS formatieren
    Antwort #11 am: 09. April 2013, 05:19:25
    Warum eigtl. die CSS-Klasse nicht in der Funktion xtc_href_link() integrieren.
    Die lässt doch bereits Parameter zu.
    Da die Links im Kategoriemenu (also die a-tags) ohnehin ein display:block; haben sollten
    - damit man mit der Maus nicht genau auf den Schriftzug zielen muß -
    läßt sich doch über eine solche Klasse alles stylen wie man möchte.
    Wo also ist das Problem ?

    Gruß,
    noRiddle

    jpx10

    • Frisch an Board
    • Beiträge: 78
    Re: Php Link mit CSS formatieren
    Antwort #12 am: 09. April 2013, 10:00:55
    @all

    Herzlichen Dank für Eure Hilfe. Matt konnte das Problem lösen. Er hat das ganze direkt im Template gelöst. Was er genau ändern wusste weiss ich allerdings nicht. Ich vermute aber, er hat die Lösung von noRiddle umgesetzt.

    Nochmals herzlichen Dank für die zahlreiche Hilfeleistung.  :-)

    jpx10

    • Frisch an Board
    • Beiträge: 78
    Re: Php Link mit CSS formatieren
    Antwort #13 am: 09. April 2013, 11:21:46
    Nochmals kurz zur Rekapitulation:

    Das meine gewünschte Änderung aktuell funktioniert, schliesse ich auf zwei Änderungen.

    1. Ohne web0null's geänderte Categories.php würde die Ergänzung im Template wohl nicht funktionieren. Aus diesem Grund möchte ich mich hiermit auch nochmals bei web0null herzlich bedanken.

    2. Die Änderungen von web0null funktionierten erst nach folgenden Anpassungen im Template:

    Bisher:
    Code: XML  [Auswählen]
    <li><div class="navcontainer"><a href="{$LEVEL3CAT.link}" title="{$LEVEL3CAT.title}">{$LEVEL3CAT.title}</a></div></li>

    Neu:
    Code: XML  [Auswählen]
    <li><div class="navcontainer"><a href="{$LEVEL3CAT.link}" title="{$LEVEL3CAT.title}" class="{$LEVEL3CAT.class}">{$LEVEL3CAT.title}</a></div></li>

    Grüsse
    Kopernikus

    web0null

    • Experte
    • Beiträge: 1.998
    Re: Php Link mit CSS formatieren
    Antwort #14 am: 10. April 2013, 04:18:39
    @noriddle,
    Zitat
    Warum eigtl. die CSS-Klasse nicht in der Funktion xtc_href_link() integrieren.
    Die lässt doch bereits Parameter zu.

    Na das wird nicht ganz funktionieren, die Parameter in dieser Funktion, sind die GET Parameter, damit kommt dann so etwas heraus http://localhost/index.php?blabla=1, und das kommt dann in href="..." rein.

    Wuff :-PP

    Gruß web0null
    1 Antworten
    2882 Aufrufe
    29. Juli 2010, 11:25:26 von armandogarcia
    7 Antworten
    5196 Aufrufe
    19. Oktober 2011, 16:19:15 von Matt
    8 Antworten
    5201 Aufrufe
    30. Mai 2012, 12:55:53 von Cosmicbase
               
    anything