
alan
Members-
Posts
854 -
Joined
-
Last visited
-
Days Won
1
Everything posted by alan
-
This KISS tagging is working really well, with just one feature that I can't crack; a summary view where each tag is shown and under it the pages that have that tag applied. I've skinned my PHP/PW-knees trying to do this but failed The following code is nearly what I want, producing this output which shows each page and under it the tags that have been applied (the opposite of what I want): echo "<h1>Tags pages</h1>"; $tag_pages = $pages->get("/tags/"); // TODO can this line and the one below be combined? $all_tags_pages = $tag_pages->children; // TODO can this line and the one above be combined? $tagged_pages = $pages->find("tags.count>0, sort=title"); echo "<dl>"; foreach ($tagged_pages as $matched) { foreach ($matched->tags as $tag_pages) { echo "<dt>{$tag_pages->title}</dt>"; } echo "<dd><a href='{$matched->url}'>{$matched->title}</a></dd>"; } echo "</dl>"; In trying to solve this I've been working on the assumption I need three loops/nested loops/tests # a list of the tag pages (the pages used to represent the tag names) # the list of tagged pages (the pages that have one tag or more applied) # for each tag page, the tagged pages that include it's tag -> output the page title I'm still working on solving this as it would round off a great little soft sub-indexing strategy, but if anyone can see the answer and can drop me a clue I would be most grateful, thanks in advance!
-
@everfreecreative Apologies you probably know this already, but, if you have easy access to make subdomains like thisone.example.com then putting demo sites in subdomains is I find much simpler as all software still regards itself as in the root (of the subdomain) and so no reconfiguration relating to stuff no longer being on the root is required. I often have dev1.example.com dev2.example.com.
-
Thanks all for your comments. @Ryan I've not touched on caching yet as I learn my way into PW and both the Cache and MarkupCache modules are currently uninstalled. I am doing a site-wide find but the only pages I was working on were, I think, both Published and visible; but some pages are hidden, /_Site_settings/ and /_Tools/ etc). This has not happened again. Re the Firefox ref in case relevant I now develop in Chrome. This was a time when I didn't distinguish what was happening as something I should try to record so I'm afraid I don't have backups of before this happened to allow me to try to reproduce. Of course if anything more comes to mind/happens, I'll post again.
-
I was trying to find pages that one or more items populated in an AsmSelect field with: $tagged_pages = $pages->find("tags.count>0"); My test kept finding the Home page that didn't have anything populated in the AsmSelect field "tags". Eventually after trying lots of alternate ways to do this search, as I'd been adding and removing fields etc, even though Home showed no items in it's AsmSelect, I added one, then deleted it, back to no items, and now the test that had appeared broken was working fine. Might this be due to caching and if so is there a way, while developing, I can globally set PW to not cache so stuff like this can't happen? Or might it be due to me adding/removing/adding back fields and somehow confusing some internal/session/other-cached settings? Tks to anyone with any ideas!
-
Thanks Pete, works a treat! And thanks for showing me my code-bloat, I'll go through that and learn for next time
-
I've made real progress (big smiles here ) but have run into a silly problem, any pointers anyone please? Background: Taking Pete's most helpful advice as a starting point, I wanted to make the focus of the tagging not the tag names but the titles of 'pages-like-this-one'. E.g. My Home page is tagged "butter" and also my Food page is tagged "butter", I wanted on my Home page to say "Other related pages: Food" and my Food page to say "Other related pages: Home". I should note in case it's relevant all pages are using one template for now (I have dropped the 'tags' template). <?php // Link to title of each page that shares one or more tags with this one // --- // find this pages tags $this_pages_tags = $page->tags; // each tag, find other pages that match the tag // TODO limit the find? foreach ($this_pages_tags as $tag) { $other_pages = $pages->find("tags=$tag")->not($page); } // output title of foreach ($other_pages as $matched) { echo "<a href='{$matched->url}'>{$matched->title}</a> "; } ?> No problem: Home and Food pages share the "butter" tag and each shows a link to the other as expected. If I also add the "marmite" tag to the Contact page then as expected the other pages do not show a link to the Contact page (as they don't share a tag). Problem: When I add the "marmite" tag to the Home page it starts showing a link to the Contact page (good as they now share a tag) but no longer shows a link to the Food page even though they also still share the "butter" tag. It's feels sort of like I am building a one-depth list when it needs to be N-depth, but I can't work out the code to address this. Any help/comments most appreciated.
-
Welcome Ryan, happy if it helps at all. And I had been adding/removing/adding/removing/adding/removing fields, templates, pages called "tags" in my (feeble) search to work out how to do what in the end Pete showed me was wonderfully simple (as I knew it would be! ) So I have zero loss in confidence from that error condition.
-
THANKS for those examples Pete, code snippets like this are really helping me help myself
-
Brilliant works perfectly, thanks Pete! And thanks for the link to the other post, gonna go read. I have one problem that is likely down to me creating/deleting pages, templates, fields called tag and tags all afternoon — each time I go to edit any page I am getting: Invalid value sent to Page::setTemplate Do you think I would be well advised restoring from a db backup? Or should I try to work out a fix in case this happens again or is of interest? Correction, this happens for some pages, just working out what the common link is... Update: Backed up and saved 'broken' db in case of help to you Pete/Ryan etc and then restored and re-created the items I needed and all works perfectly, thanks again!
-
Oo, thanks I can see. So far so good
-
THANKS Pete, off to go and try this, cheers!
-
I am trying to implement a KISS (Keep It Simple Stupid) tagging system, one depth, i.e tags not hierarchical categories. Each page would display any tag that was added to it as a link; the link goes to a page where all other pages sharing that tag are listed, quite basic. In my attempts to do this I have been reading up, posting, getting help (thank you patient helpers), trying, failing and have slightly run aground. I know instinctively from the little I've done with PW that this is going to be easy, when I can see 'how'. These are the three threads I've been looking at, but perhaps each was not quite what I am trying to do and that, plus my PHP weakness, stopped me succeeding. These are my assumptions as to what I would do: have an AsmSelect field called "tags" on each page in the Admin so content authors may select or add tags per page have a page below Home called "tags" which will have a child page per tag don't have a .php file for the "tags" page (is that right?) don't have a .php file for each children page of the "tags" page use a file-less template for the "tags" page and children pages and that template to include only the title field (is that right?) use my main/single .php template file for all pages and detect if it is being used to display tag-related content and change its outs put accordingly. If you're able to point me to a thread I may have missed containing code samples so someone like me can get going, or post a few snippets to show me the basic code and correct any of my assumptions that look wrong I would be very grateful. Cheers, -Alan
-
@apesia Thank you, so simple it's embarrassing. @Soma NO problem with confusing me, it does me good to stretch my brain! And also I see now how limiting the search is a good idea (important indeed). And previously I didn't see your last line [$pages->get("/tags/")->find(...)] —my bad! I will go and try to implement that. That together with @apesia's note on how to output tags only leaves me needing to work out how to link tags to an 'Other pages sharing this tag' type page. I will try to do that and only post here if I get stuck, er, which might just happen Thanks again!
-
Thanks Soma, I think I may be out of my depth but I'll try to comment and I hope I make sense... I am not using a Template called tag or one called article, so I assume(?) I can delete those parts of the finds (also I changed: tag=$tagpage to tags=$tagpage otherwise I got an error). With these changes I am no longer getting any errors, thank you! But I now see the code does not actually output anything -- I am trying to get out a list of tag names for the page being viewed and while I am getting no errors I'm also not seeing anything. I assume I need to do something with $related_articles, does that sound right so far do you think?
-
DOH! Is it becuase 'tags' field is an asmSelect field and not a plain text field or textarea field?
-
Thanks Soma I checked and the only differences I can see between the 'tags' field and the 'title' field is that 'title' had Autojoin and Global ticked. I tried ticking these (in case one/both were the definition of a fulltext field) but the error is still present. I tried following the advice here: and changed the selector from *= to %= but the error is still present. Any other ideas greatly appreciated
-
PHP is cleverer than I am I think In an attempt to work out what I am doing wrong I have moved my parent tag page to directly under Home and renamed it to simply 'tags'. Using this code I am getting: Error Exception: Operator '*=' is not implemented ... etc So I edited it like so to try and see if I could help myself: $related_articles = array(); $tags = explode(',', $page->tags); foreach ($tags as $tag) { $tag = trim($tag); echo $tag; // $articles = $pages->find("tags*=$tag"); // foreach ($articles as $article) { // if (!isset($related_articles[$article->id])) { // $related_articles[$article->id] = $article; // Not sure if this saves any overhead - just makes sure we're not overwriting duplicate array entries if 2 articles have the same tags // } // } } ...the commenting out just to stop the error and the addition of echo $tag; to see if that told me anything. Using the edited code I am getting no errors and the IDs of the pages that any given page is tagged with are output, which is good as far as it goes. I've tried hard to solve the error, searched and read but my Achilles PHP-simpleton-heel has thwarted me. Does anyone see why I may be getting this error, please and thanks?
-
Thanks Soma for clearing that point up for me
-
Ah I understand, thanks diogo and NO need to apologise!
-
Excellent. Correct. I don't understand that, but I'm experimenting with tagging today so I will see if I can understand it when I've done a little more learning. Thanks diogo for the help.
-
I'm using this approach in order that I may tag pages that share a common theme. I've not got to writing any code yet, just setting up fields/templates. I have a hidden parent page called 'Tagging' and under it a page per tag. But when I am in the editor and adding a new tag (page) or two, the resultant pages are not set to 'Hidden'. I've tried to make them hidden by changing my template Access settings but that was only an educated guess — is there a way to make pages create pre-set to hidden, or, as the pages are under a hidden parent am I safe to not care that they are not hidden? Any comments gratefully received Edit: Larger question may be -- am I wrong to have the parent of the tags as a hidden page in my hidden '_Tools' section rather than calling it, say, 'tags' and having it visible immediately under Home?
-
@renobird I also am a TXP person and also have just started with PW, and I'm mightily impressed. I'd already bookmarked the page noted by @formmailer for a re-read — the first time I ran through it it left me a bit confused, I think party due to my limited intellect and also as it's discussing likely a very powerful way to use PW. As far as static reusable content goes, I believe it's a widely adopted approach to use pages for all sorts of stuff, from selects to static content. E.g. you could create a top level page called Statics and under it have a page per lump of static content you may wish to reuse around the site. The page with the content could have any fileds you wish as it can use any template. Sorry I'm not more up on PW to give more advice and I hope that's not been too obvious and is useful. Enjoy PW, I am!
-
Code to detect a populated repeater and then output repeated items
alan replied to alan's topic in General Support
I have the approach I was trying for (using a Repeater) working beautifully simply courtesy Ryan's code plus an adjustment for using the select, thanks again everyone for all comments! foreach($page->segments as $segment) { $width = $segment->segment_width->segment_data; echo "<div class='grid_$width'>"; echo $segment->segment; echo "</div>"; } I'm going to write up how I did this (the select with the etc), as much for me as an aide memoir as anything, and when I have I'll link it here in case it helps anyone else. -
Code to detect a populated repeater and then output repeated items
alan replied to alan's topic in General Support
THANKS diogo, that looks great also Thread bookmarked -
Code to detect a populated repeater and then output repeated items
alan replied to alan's topic in General Support
Fantastic! Yes you are exactly correct Ryan and thank you for again showing how beautifully simple PHP + API (plus cool Repeater fn) makes such a task in PW. And sage advice also re getting it working then adding the select afterwards. And yes, no float clearing is required with the grid. Thank you very much indeed for this help, code squirrel-ed away in snippet store so I learn from it Cheers! -Alan