From 1f8ea70b40f68d3248b45bdc3a0a3b24cdc11f44 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 20 Jul 2023 00:04:11 +0200 Subject: [PATCH] define content for navigation --- lib/WPMenu.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/WPMenu.py b/lib/WPMenu.py index 944d2f4..c61cee5 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -171,6 +171,9 @@ class WPMenu: exist = False if exist is False: for i in ["categories", "tags"]: + typeId = "category" + if i == "tags": + typeId = "tag" for index in range(1,10): try: params = {"search":title, "per_page":"100", "page":index} @@ -183,7 +186,8 @@ class WPMenu: self._logger.info("{0} info : {1} {2} {3}".format(self._name, j["name"], j["slug"], title)) if j["name"] == title or j["slug"] == title: self._logger.info("{0} : comparaison ok : {1} {2}".format(self._name, j["id"], i)) - idMenu = {"id": j["id"], "type": i, "link": j["link"]} + + idMenu = {"id": j["id"], "type": typeId, "link": j["link"]} exist = True else: break @@ -254,8 +258,18 @@ class WPMenu: if idMenu["id"] != 0: menu[i] = {"id":idMenu["id"], "type": idMenu["type"], "title":menu[i]["title"], "link":idMenu["link"], "children": menu[i]["children"]} + navigation = '' for i in menu: self._logger.info("{0} Menu parent {1} with id {2} and type {3} and link {4}".format(self._name, i["title"], i["id"], i["type"], i["link"])) + if len(i["children"]) > 0: + navigation = navigation + " \n\n".replace("label-string", i["title"]).replace("id-string", str(i["id"])).replace("url-string", i["link"]).replace("kind-string", i["type"]) + else: + navigation = navigation + " \n".replace("label-string", i["title"]).replace("id-string", str(i["id"])).replace("url-string", i["link"]).replace("kind-string", i["type"]) for j in i["children"]: + navigation = navigation + " \n".replace("label-string", j["title"]).replace("id-string", str(j["id"])).replace("url-string", j["link"]).replace("kind-string", j["type"]) + self._logger.info("{0} Menu children {1} with id {2} and type {3} and link {4}".format(self._name, j["title"], j["id"], j["type"], j["link"])) + if len(i["children"]) > 0: + navigation = navigation + " \n" + self._logger.info("{0} : {1}".format(self._name, navigation)) \ No newline at end of file