-
Posts
10,902 -
Joined
-
Last visited
-
Days Won
349
Everything posted by adrian
-
If I am understanding you correctly it is quite simple to do by setting a variable to the current category and then only echo out the category title if the category is different to the category from the last echo'd result. $current_category = ''; foreach($wor as $result) { if($result->cat != $current_category){ echo "<span class=\"catem\">{$result->cat->title}</span>"; } echo **all the name, location, result output** $current_category = $result->cat; } Hope that makes sense and works for you.
-
Are you getting errors when trying to delete or add new repeater fields, or is just nothing happening? Sorry - you show the error in the subject I really haven't used repeater fields much at all, but if you are having problems deleting existing fields, you can do that through PMA as well. I wouldn't recommend deleting anything through PMA generally, but since you have already ventured in there and deleted all those pages, it sounds like that might have broken some things already anyway. Go into the "fields" table and delete the appropriate lines as well as deleting the "field_fieldname" tables. Or if you are cautious, wait for a more authoritative answer
-
This is still not really finished. It definitely works and has been tested on a couple of different sites for several months now, but I think it still needs some refining before being ready for prime time. It is now on GitHub: https://github.com/adrianbj/ProcessPDFImageCreator Will wait for module directory submission until I get time to make some refinements though.
-
A php function not working inside a template?
adrian replied to FuturShoc's topic in General Support
Actually I think it is kind of a useful example that highlights what Martijn and I said above. ucwords won't work on capitalized strings, which is why that example of kongondo's doesn't show Meine Seite -
A php function not working inside a template?
adrian replied to FuturShoc's topic in General Support
Is the page title already all caps? ucwords needs a strtolower first if that is the case. Although you tested diogo's suggestion, so I am guessing this is probably not the problem unless the string you tried was all caps as well. Do other php functions work in that context, or is it just ucwords that doesn't work? -
OK, the predefined and custom formatting options have been added and pushed to github / modules directory. Lots of changes - I have updated the first post to reflect these. If by chance you have started using this already, it might pay to delete any existing fields and recreate them. Not sure if there will be issues or not, but I had to change the db field type from "int" to "char" so it could handle leading zeros. Would really appreciate a code review from those more experienced in module development to see if there is anything I could have done more efficiently.
-
You can leave the setting at 0. Using first(), last(), or eq(n) will allow you to access whatever image you want from a multiple images field. ->url will get you the path from the root. eg. /site/assets/files/xxxx/filename.jpg
-
Ok, I think I might know what is going on. You say "If my image is called image1-cover". Is "image1-cover" the filename of the image, eg image1-cover.jpg or is it the name of the image field in PW? You need to reference the image by its field name. On a page you can do: echo $page->image1_cover->first()->filename; This line references the current page, then the image field name (the first image if the field is a multiple image field), then the filename of that image. You can also reference fields from other pages, but I'll leave it simple for now. Does that help?
-
I haven't updated the code in the modules directory yet, but take a look at the attached screenshot. I have set up custom formatting options, similar to the way the DateTime output formatting options work. The user can choose from some pre-defined options, or edit an existing format to output as they want. So now you can choose an output format and then output the formatted phone number on the front-end with: $page->fieldname->formattedNumber or you can manually format by using the component parts as described in the initial post above. The formatted version is generated on the fly and not stored in the database. Now I am wondering how many predefined formats I should set up. There are quite a lot of different formats, but not sure that there are any official standards: http://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers Anyone out there an expert on phone number formats, or have any strong thoughts/ideas on this? Also, does anyone have any comments on the format code syntax I set up, which you can see in the screenshot. Does this seem intuitive? Any other ideas? I might attach the revised code here soon and ask for some feedback before updating it on github/module directory. One more thought - wonder if it might be useful to have a format over-ride option - an extra subfield that allows page specific formatting of a phone number - might be useful for example for an international business with office around the world to be able to apply different formats on different pages. Thanks
-
Bill, Are you aware of the difference between single and multiple image fields? Check the "Maximum files allowed" field on the details tab of your image field. If it is set to anything but "1" then you will need to do something like: <?php echo $image1_cover->first()->url; ?> If it is "1", then you must omit the "first()" I have used "url" as I would imagine that you don't really want "filename" as it would look something like: /var/www/root_folder/site/assets/files/xxxx/filename.jpg Does that help?
-
Repository of php Scripts for Templates
adrian replied to thetuningspoon's topic in Wishlist & Roadmap
I just wanted to add my vote for this functionality. Seems like it might be a fairly easy modification, or perhaps addition to the code that runs the modules directory. Of course it would also be awesome to also be able to browse these snippets through the PW admin like the modules manager. -
I was initially thinking about storing a formatted number as an extra field so you could simply do: $page->fieldname->formatted_number, but for the sake of flexibility and reducing database redundancy, I went with leaving the formatting to the output. Any thoughts on this? Now I am thinking that maybe I could go with something like the datetime field type's Output Format options and set up a few common formats to choose from as the default output, or the ability to define a custom output format in the field's details tab. This has been done and is now described in the initial post above. Maybe getting carried away now , but also thinking about detecting the end user's country and determining whether the country code needs to be added to the front-end output or not. Any thoughts / ideas?
-
Phone Number Fieldtype A new fieldtype to enter phone numbers with 4 integer values for country, area code, number and extension and format the output based on predefined or custom options. StyledOutput The most common usage option will be: echo $page->fieldname //eg. +1 (123) 456-7890 x123 This provides a fully formatted phone number, based on the output format chosen from module's configuration page, or with the format override option (if enabled), when entering a phone number on a page. This is a shortcut that produces the same output as: echo $page->fieldname->formattedNumber //eg. +1 (123) 456-7890 x123 Alternate styled options are: echo $page->fieldname->formattedNumberNoExt: //eg. +1 (123) 456-7890 echo $page->fieldname->formattedNumberNoCtry: //eg. (123) 456-7890 x123 echo $page->fieldname->formattedNumberNoCtryNoExt: //eg. (123) 456-7890 echo $page->fieldname->unformattedNumber: //eg. 11234567890123 echo $page->fieldname->unformattedNumberNoExt: //eg. 11234567890 echo $page->fieldname->unformattedNumberNoCtry: //eg. 1234567890123 echo $page->fieldname->unformattedNumberNoCtryNoExt: //eg. 1234567890 Of course the actual output is determined by the selected format output Raw Output You can output the values for the component parts of the phone number like this: echo $page->fieldname->country; echo $page->fieldname->area_code; echo $page->fieldname->number; echo $page->fieldname->extension; Output for mobile compatibility To get iOS and other mobile platforms to recognize numbers and be able to automatically dial them, use something like this: echo '<a href="tel:+'.$page->fieldname->unformattedNumberNoExt.'">'.$page->fieldname->formattedNumber.'</a>'; Selectors for searching The component parts can be used in selectors like this: $pages->find("phone.area_code=123"); Field Settings There is a field settings for the width of the inputs in pixels. There is a field settings for the width of the inputs in pixels. You can also choose whether to display the country and extension fields for input. Off by default. There is an additional checkbox that determines whether there is an option to override the default format option on a per entry basis, which will be useful when styling phone numbers from different countries on the one website. Off by default. Custom formatting options On the module's configuration page you can choose from predefined formats, or create custom formats using syntax like this: {+[phoneCountry] }{([phoneAreaCode]) }{[phoneNumber,0,3]-}{[phoneNumber,3,4]}{ x[phoneExtension]} which generates: +1 (123) 456-7890 x123 Each component is surrounded by { } The names of the component parts are surrounded by [ ] Two comma separated numbers after the component name are used to get certain parts of the number using php's substr function, allowing for complete flexibility. Anything outside the [ ] is used directly: +,-,(,),x, spaces, etc - whatever every you want to use. There are lots of complicated rules around numbers changing when dialed from different locations. A simple example is for Australia. When dialing from within Australia, area codes start with a 0, but when dialing from another country, the 0 must be omitted. You can write a simple format to handle this. The following truncates the first number from an Australian two digit area code: {+[phoneCountry] }{([phoneAreaCode,1,1]) }{[phoneNumber,0,4] }{ [phoneNumber,4,4]}{ x[phoneExtension]} which generates: +1 (7) 1234 5678 x123 even though the full "07" is stored in the area code field. Where to get Available from github: https://github.com/adrianbj/FieldtypePhone And the modules directory: http://modules.processwire.com/modules/fieldtype-phone/ To Do Need to increase the number of pre-defined formats. There seem to be so many options and no real standards, so I thought rather than create a huge list of options that no-one will use, I thought I'd wait and get you guys to contribute them as you need them. Either post your formats here, or send me a PR on github and I'll add them. How to install Download and place the module folder named "FieldtypePhone" in: /site/modules/ In the admin control panel, go to Modules. At the bottom of the screen, click the "Check for New Modules" button. Now scroll to the FieldtypePhone module and click "Install". The required InputfieldPhone will get installed automatically. Create a new Field with the new "Phone" Fieldtype. Choose a Phone Output Format from the details tab. Acknowledgments This module uses code from Soma's DimensionFieldtype and the core FieldtypeDatetime module - thanks guys for making it so easy.
- 138 replies
-
- 15
-
I guess my main concern is that dimensions for things are rarely whole numbers (integers), so I am not sure how useful the module can be in its current form. Maybe not an issue in the metric world (where I was born and raised) where you could specify dimensions in millimeters, but now that I live in a backward imperial country (practically, although not officially), and we are stuck with inches as the smallest unit of measurement, it becomes a problem. I am not completely convinced on these multiple input field types. I have always set up dimensions as three separate fields and done the calculations at runtime (I also don't like the redundancy of storing calculated values), but I was looking for a way to use the volume in a selector and thought this might be a good approach. Makes me wish for the ability to do math and apply other calculations / functions to the items in a query, but you have heard my thoughts on that before EDIT: Apologies - I just properly read and understood your instructions - you are saying to store as 538 and format on output to 5.38
-
Hey Soma, Just curious why your module only supports integers. I'll probably modify for my needs, but am wondering if there was some reason I am overlooking.
-
Your first non-working code block doesn't foreach through the $languages array and so $language is probably never defined. As for the variables being printed in the double quotes - that is how php works. In double quotes it works as is. In single quotes you need to do something like: echo '<li><a href="'.$page->url.'">'.$language->title.': '.$page->title.'</a></li>'; Hope that helps.
-
Weird. Actually now that I think about it, I assume the error you were getting was in the admin, and not on a front-end page, so it shouldn't matter what version of jquery you set in your front-end templates. Not sure why that module is causing that problem though - it works fine for me.
-
Suggests to me that you are running a newer version of jquery that no longer supports "live". Have you replaced the script code for jquery or are you using the default that comes with the default PW profile?
-
Not sure if it will work in this case, but have you tried an apache based solution: https://www.google.com/search?q=php+subdomain+session&oq=php+subdomain Some of those results suggest apache and others make use of php options. Might be something in there of use.
-
Assets not accessible - sometimes/mobile devices???
adrian replied to r2d2's topic in General Support
Sounds to me like the cms subdomain is not accessible outside your network which is why you can't access it on your mobile device and we can't access it at all. -
Hi and welcome to PW. Simply set up a new permission called: page-publish and make sure that is checked for the admin user's role and unchecked for the others.
-
Attaching iteration number to foreach-generated HTML-tags.
adrian replied to NoDice's topic in Getting Started
Not exactly sure what you are after, but a typical approach to numbering is: $i=1 foreach($items as $item){ echo '<li>Item#' . $i . ': ' . $item->title . '</li>'; $i++; } Hope that helps. EDIT: Just saw your second post, and I don't think I really understood what you are looking for. It sounds like you want to generate the number via the admin, rather than on the front-end. Is that correct? -
I know this doesn't really solve your issue, but it is another tool that you might be able to make use of: http://modules.processwire.com/modules/page-list-image-label/
-
Ordering by date reversed, then time normal order
adrian replied to adrian's topic in General Support
Excellent - I am not sure the best way to achieve this yet, but if you can make it possible to hook into the selector parser, I would happy to have a go a writing a module that allows for using SQL directly in selectors, or at least using mysql function/operators. Not sure the best option yet. The former could be very powerful, but obviously more complex to integrate without problems. I'll have to start looking through the core and getting an idea how the parser works. -
Hey Ryan, Thanks very much for taking care of this change. Regarding the title limit - every time I have installed PW with the default profile or the new Foundation profile, the title field already has maxlength set to 255, not 2048. Here is the relevant line in the install.sql file: INSERT INTO `fields` (`id`, `type`, `name`, `flags`, `label`, `data`) VALUES (1,'FieldtypePageTitle','title',13,'Title','{\"required\":1,\"textformatters\":[\"TextformatterEntities\"],\"size\":0,\"maxlength\":255}'); Also, I am not really sure how relevant this is: CREATE TABLE `field_title` ( `pages_id` int(10) unsigned NOT NULL, `data` text NOT NULL, PRIMARY KEY (`pages_id`), KEY `data_exact` (`data`(255)), FULLTEXT KEY `data` (`data`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; I know it is only setting the data_exact key and not the field length, but is there any reason to limit this to 255?