We wanted to share some search information used by other users of this blog, in case what other people are searching for, might be the thing you didn’t know that you wanted to search for. This is human nature. We learn from each other, and that is why “trending” is such a big word in I.T. these days.
We’re going to start, limiting the pool of information this functionality reads its information from, to those new “Title RE” (ie. regular searches of Blog Posting Title) searches we introduced when we presented WordPress Blog Posting Title Regular Expression Search Primer Tutorial.
So there are two parts to this functionality, those being …
- the collection of “Title RE” search information to the web server … we pick a flat file source of that data … which is then read by …
- reporting of trending “Title RE” searches made at the blog, reading that dynamically changing pool of “Title RE” search data
… consecutively handled in …
- (good ol’) header.php of WordPress theme TwentyTen … to gather data … as per …
function asksr() {
var av=prompt('Blog Posting Titles matching Regular Expression?', document.getElementById('s').value);
if (av != null) {
if (av != '') {
if (av.substring(0,1) == '.') {
location.href='http://www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(String.fromCharCode(92) + av + 'fRoM');
} else {
location.href='http://www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(av + 'fRoM');
}
}
}
}
… helping out mapper.php, that changed in this way to accommodate along with the new … - trending_on_wordpress.php … with its live run for this blog’s trends … PHP to report on those trends via a Javascript alert box window and Google Chart Histogram Chart … thanks to this very useful link regarding some of the suavest logic used in it
So one last thing is, where do we “store” this functionality? We thought, put it on the “All Posts” main menu as a submenu option, so that it becomes a piece of functionality only causing web server processing activity loading when a user chooses to ask for this.
Previous relevant WordPress Blog Posting Title Regular Expression Search .htaccess Tutorial is shown below.
As we pick up from yesterday’s WordPress Blog Posting Title Regular Expression Search Primer Tutorial with explaining the functionality behind our new WordPress Blog Title Regular Expression Search functionality you can …
- take a peak at the URL created during its use on the way .. via (header.php’s Javascript HTML select element onchange event logic) …
function asksr() {
var av=prompt('Blog Posting Titles matching Regular Expression?', document.getElementById('s').value);
if (av != null) {
if (av != '') {
if (av.substring(0,1) == '.') {
location.href='http://www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(String.fromCharCode(92) + av);
} else {
location.href='http://www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(av);
}
}
}
}
… to showing the top of the page HTML select element dropdown … or, be a smart Alec and … - take a peak at the second last word of today’s blog posting title
… to get the hint that, today (as with WordPress 4.1.1’s WordPress Blog Posting Title Regular Expression Search .htaccess Tutorial), we have on our hands an example of the use of an Apache web server .htaccess approach to URL processing and navigation control.
The use of .htaccess files in Apache web server environments is quite a big subject, and for more far reaching detail than what we provide today, we would like to direct you towards this useful webpage (and while you are at it, read about our upgrade from WordPress 3.0.3 to WordPress 4.1.1 and some .htaccess work via the blog posting thread ending at WordPress Upgrade Crontab Curl Tutorial). What can you do within a subject area you want to learn? Stay informed, read, consult or … take leads from others, and by so doing, know more the specifics of what you need to read and research, we hope?! So it was with us, taking leads off something we’d done earlier taking leads off what WordPress had shown us was possible in that ‘earlier on’ period.
We find .htaccess work very satisfying, as it is making URLs look less ‘manufactured’ … though, today, it must be admitted, an interim URL we use obfuscates that elegance a fair bit. Nonetheless, having these ‘magical’ URLs with no ? nor & (quite often) doing these strange things happens (with .htaccess work) because … the .htaccess mapped URL’s PHP or HTML code is passed the original URL and it behoves that mapped code to make use of that fact … in other words, the address bar URL will still be the elegant non-?-& URL that the PHP or HTML’s document.URL sees and can ‘chameleon fashion’ change its guise, according to … and we go and ‘change the guise’ to a self recalling arrangement of a URL that does contain a ? and is thus available to the PHP we write in the global variable $_GET[‘pm’] as per (hint: mapper.php’s) code snippet …
if (isset($_GET['pm'])) { // recall scenario
// populate the HTML select element dropdown via $_GET['pm'] ... rest assured, PHP's eregi is used in this logic
} else { // got here via .htaccess in http://www.rjmprogramming.com.au/itblog/match/ web server directory
// recall yourself via location.href='http://www.rjmprogramming.com.au/itblog/match/mapper.php?pm=' + document.URL.replace(''http://www.rjmprogramming.com.au/itblog/match/', '');
}
Okay, so did you “take a peak at the URL created during its use on the way to showing the top of the page HTML select element dropdown”? If so you’d have found a sequence of URLs, the first two really hard to get a glimpse of …
- http://www.rjmprogramming.com.au/itblog/match/Python
- http://www.rjmprogramming.com.au/itblog/match/mapper.php
- http://www.rjmprogramming.com.au/itblog/match/mapper.php?pm=Python
… because it all happens so fast, and we’ve helped you out in today’s tutorial picture imagining it happening. But what happens? Well, the URL’s http://www.rjmprogramming.com.au/itblog/match/ underlying web server directory has a special file, at least to Apache web servers, and it is called .htaccess and for the scenario above it comprises …
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /itblog/match/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /itblog/match/mapper.php [L]
</IfModule>
# END WordPress
… about which you need to see that Apache’s mod_rewrite module needs to be active for this .htaccess file to be noticed and that “RewriteRule . /itblog/match/mapper.php [L]” is the bit that spurs the …
- http://www.rjmprogramming.com.au/itblog/match/Python
- http://www.rjmprogramming.com.au/itblog/match/mapper.php
… mapping taking place, and is the doing of the .htaccess file, while the rest happens within our homegrown mapper.php where its navigational progression …
- http://www.rjmprogramming.com.au/itblog/match/mapper.php
- http://www.rjmprogramming.com.au/itblog/match/mapper.php?pm=Python
… can only feasibly be guessed at by mapper.php because the previous “http://www.rjmprogramming.com.au/itblog/match/Python” URL is available to it in the Javascript DOM client “document.URL” global … cute, huh?! And, that being the case we know to construct HTML select element dropdown contents based on “Python” and to populate an HTML iframe below with the landing page of the blog, awaiting any user specified instructions.
You may well reason that you don’t have to involve .htaccess Apache methods to get this job done, and you’d be right, but the topic can be extremely useful regarding Apache web servers, like we have at www.rjmprogramming.com.au … and so we thought we’d show you some details here, and we hope you like it.
Did you know?
Were you a blog reader here when we introduced WordPress version 4.1.1 into the equation? Do you recall us making URLs …
… “equate” to the same web (blog) application webpage? Please read the “Did you know?” of WordPress Upgrade Implications Tutorial for more information here, but the gist of making this happen was to place into http://www.rjmprogramming.com.au/itblog/ URL’s underlying web server directory the .htaccess file as below …
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /itblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ITblog/index.php [L]
</IfModule>
# END WordPress
… which amounts to a very similar concept to today’s mapper.php for our Blog Post Title Regular Expression Searches scenario, and is a lesson in how individual web server directories can have tailored .htaccess functionalities.
Previous relevant WordPress Blog Posting Title Regular Expression Search Primer Tutorial is shown below.
One of our chief aims with this blog is to send the user off on a themed ‘thread’ of inquiry. What came, by default with our WordPress TwentyTen themed blog was to categorize via …
- Category
- Tag
- Search (string)
… and then … some time back … sun comes up, sun goes down x 100’s … we allowed a Search (string) arrangement within one of the other two ‘parent’ searches … and today … da da da da da, da da da … we allow a Regular Expression search of Blog Posting titles … because …
- it fits in quite nicely with our long-winded blog posting title regime, which has been designed to tell it like it is … but not great for SEO (you should be warned) … and …
- we’ve always felt that an exploration of a topic like “Python”, for example, will not necessarily fit into a “Category” nor necessarily even a “Tag” scenario nearly as well, for us, as to allow a (Regular Expression) search of Blog Posting Titles for “Python”
… as well as the cute feature that, because it is using PHP Regular Expressions via the eregi method, you could narrow the search via ^Python as an example to ensure Blog Posting Titles have to start with “Python”.
There is a dual purpose to this work, but we’ll just be discussing the “interface” to the WordPress blog today, and detail something else regarding it tomorrow. So for today, we add a new HTML input element type=checkbox next to the blog’s Search input textbox, and off whatever might have been entered as text into that field as the default string for a Javascript prompt window asking of what Blog Posting Title Regular Expression Search they want to perform, and this sends the user to a new webpage consisting of …
- one HTML select element dropdown of matching Blog Posting Titles … under which is …
- one HTML iframe element initially showing the blog’s landing page but ready to be repopulated via any choice the user makes regarding the HTML select element dropdown above … like a television with “top” control
That HTML input element type=checkbox (that you can see in today’s tutorial picture) is coded (in … you guessed it … good ol’ header.php) as below …
<input title='WordPress Blog Posting Title RegExp search ...' onclick="asksr();" type='checkbox' id='scbtype' value='Title RE'></input><a style='cursor:pointer;text-decoration:underline;' title='WordPress Blog Posting Title RegExp search ...' onclick="asksr();">Title RE</a>
We’ll be taking off from this point explaining more about the architecture behind this functionality tomorrow. But you being here, up at the Search input box you can try out what we mean, to see all this in action. And it may be worth considering … a “Regular Expression” each day keeps you Regular … yes, you heard it first here, folks!
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.