Random Musings of Brian A. Thomas. Love for Ari and Sidd.
PHP
Fixing GStyles
Oct 12th
I am working on fixing the theme I am using, GStyles (available here) and trying to make it work with WordPress 2.3.
So far I have fixed index.php and singles.php.
Here is an original code snippet from singles.php (sorry, the code runs over the edge, the theme is fixed width so it runs over... I might make this column flexible in due time, one thing at a time... or see if there is a "word wrap" feature in the program highlighter)...it should be the same in index.php:
-
<small>Category: <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?><br />Tags: <?php if ( (function_exists('UTW_ShowTagsForCurrentPost')) ) { ?>
-
-
<?php UTW_ShowTagsForCurrentPost("commalist") ?>><?php }?></small>
This was fixed in my new version to look like this:
-
<small>Category: <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?><br />
-
<?php if(function_exists('the_tags')) {$my_tags = get_the_tags();if ( $my_tags != "" ){ the_tags('Tags: ', ', ', '<br />'); } else {echo "Tags: None";} }?>
-
<?php if(function_exists('UTW_ShowTagsForCurrentPost')) { echo 'Tags: ';UTW_ShowTagsForCurrentPost("commalist");echo '<br />'; } ?></small>
That should allow it to fall back to UTW if somebody is still using an older version of WordPress. However, I don't have an old install to test it on, but near as I can tell it should be good.
I am now working on fixing the functions.php and finding a fix for the post2cat problems in it.
The problem with GStyles in WordPress 2.3 as it stands now also comes from the following in singles.php:
-
<?php
-
-
if ( is_single() or is_page() ) {
-
-
-
$relatedposts = cattag_related_posts();
-
-
if ($relatedposts === false) {
-
-
// echo '<p>No related posts</p>';
-
-
} else {
-
-
echo '<div class="related-posts">
-
<h2>Related posts:</h2><ul>' . $relatedposts . '</ul>
-
</div> <!-- [related-posts] -->';
-
-
}
-
-
}
-
-
}
-
-
?>
The fix is simple enough for now, just take that bit out. It kills the Related Posts function, but cattag_related_posts needs the post2cat. Now that is the part that may be past my programming experiences so far... then again, I did figure out how to get the rest working.
Trying to Write My Own Widget
Dec 24th
Calling all WordPress Widget experts, I am trying to write my own widget, but I am not having luck. I get it to show up in the plugins and activate it, but it doesn't show on the widget list.
I know about Chris Johnson's Tag Cloud Widget, but the cloud doesn't show for one thing, and the other is that I don't want it weighted, I want it shown in alphabetical order. It shows the title and nothing more using his... Okay, I got it to display by changing the display from 1 to 50, but that doesn't do a display all like 0 was supposed to do... Okay, I also got it to display in alpa order so I guess the code below is moot. ![]()
The code appears below the break, with a few comments after the code.
More >
More PHP Editing
Aug 2nd
I edited the PHP on the WP-Amazon Plugin for WordPress. I wanted to achieve two things. One, when adding an image, I wanted the text to follow it. Two, I wanted to have it display the name of the product in the title attribute of the link, that is, when one hovers over the link, I wanted the title to display, rather then the default of "View product details at Amazon".
Here is the new improved code:
-
function generateHTMLCode(format,prodname,url,imgurl) {
-
if (format=='link') {
-
html = '<a href="'+url+'" title="Amazon.com - '+prodname+'">'+prodname+'</a>';
-
} else {
-
html = '<a href="'+url+'" title="Amazon.com - '+prodname+'"><img src="'+imgurl+'" alt="'+prodname+'" /></a><br />'
-
+'<a href="'+url+'" title="Amazon.com - '+prodname+'">'+prodname+'</a>';
-
}
-
htmlCode = document.getElementById("htmlcode")
-
htmlCode.value = html;
-
}
Here is the old code so one can find it. It should be around line 190 or so (for version 1.3.2 anyhow)
-
function generateHTMLCode(format,prodname,url,imgurl) {
-
if (format=='link') {
-
html = '<a href="'+url+'" title="View product details at Amazon">'+prodname+'</a>';
-
} else {
-
html = '<a href="'+url+'" title="View product details at Amazon"><img src="'+imgurl+'" alt="'+prodname+'" /></a>';
-
}
-
htmlCode = document.getElementById("htmlcode")
-
htmlCode.value = html;
-
}
I am still looking for a way to change the link to a more basic link, so Amazon's new Product Preview will work properly. However, for some reason I can't figure out where it is making the full link...
More Editing Now Reading Code
Jun 3rd
With the theme I am using, the sidebar got stuck below the content. Now the sidebar is aligned along the top with the content. I also had to add code to let it know there was a sidebar to the right. The Library page looks much better now I think. If it wasn't for the theme I used, it probably wouldn't need edited...
Edited to clear why things were done.
Fixing Now Reading
Jun 1st
As I mentioned before I use the Now Reading plugin for WordPress here. However, it has a small anoyance. It linked to the "You may also be interested in these items..." page, rather than the item's detail page. If the user didn't click "add to cart" and looked at the "also interested in these items" stuff, it would cut your earnings from 15% to only 5%. Then again an article titled Amazon Associates Beware states:
The "ref=nosim" links apparently work correctly, although they are undocumented on the Associates site. However, it's unclear as to whether you make more money from using them. You're more likely to make that 15%, but you might make more in the aggregate from the recommended items you get using the first method. That is, the number of people looking to buy that item right away (say, 2 people counted at 15% apiece for a $15 item for a total of $4.50) might be offset by the number of people looking to browse and then buy (10 people counted at 5% apiece for a $15 item for a total of $7.50). The reports for my site at Amazon show that people who click through seem to browse and then buy rather than buy directly...I just need to get them into the store and Amazon will take care of the rest.
So perhaps it is best to leave it as is, especially on a site like this where book sales are not a real focus.
Anyhow, I applied the "ref=nosim" bit to the Now Reading plugin. I applied it to template-functions.php file. I added it to the function book_link funtion after it puts in the books ASIN number. Here is the fixed section of code:
This may or may not be helpful, but I prefer to go to the books detail page myself... at least for now. ![]()
EDIT: Of course it would perhaps be best to make it an option in the options panel, but that is too much work for me at the moment. Also, I might try to fix the links some of the other stuff makes to be cleaner like that.
I Modified GeSHi’s C# File
May 7th
As noted before, to post code in WordPress, I use the ig:Syntax Hiliter plugin. It uses the GeSHi engine.
I recently decided to modify the way it colors C# code. In particular I wanted to separate XML style comments from regular comments.
To that end I modified the PHP code in GeSHi's C# file.
More >
Categories moved to top of posts
Oct 20th
I did some editing of the PHP source code for WordPress here and moved the categories listing to the top, added the who it was posted by... and at one point had the time, but the time is off by about 2 hours, which is odd since it is set for Eastern... of course it may be getting the time stamp from the server, in which case... I am not sure where it is.
PHP editing of the site
May 2nd
Seems the site was not validating as valid XHTML. I had to edit some of the PHP code to fix it. Seems when I added the calendar back in (it is off by default in WordPress 1.5) I forgot to keep it in the proper flow of things. I also had to edit the Amazon Wishlist program to become valid XHTML. Anyhow, things validate again... if anyone cared.
Scripturizer Revised again
Jan 19th
The awesome WordPress plugin, Scripturizer, has been revised again (code here). Seems somebody named Brian Thomas helped them make it XHTML compliant... oh wait... that's me!
Editing Scripturizer
Jan 17th
I had to edit the PHP code in Scripturizer to make it validate as XHTML.
The problem is that some of the sites use an ampersand (&) as part of their URL. XHTML doesn't allow that in the code, and the & needs changed to &. A subtle difference to be sure, and what comes up on the address bar is still the same. However, it is a simple fix. So far all I fixed are ones going through Biblegateway, which is the one I would normally use.
On version 1.5, my copy has line 157 reading as follows:
$link = "http://biblegateway.com/bible?version=$translation&passage=";
I changed that to:
$link = "http://biblegateway.com/bible?version=$translation&
and viola, it now validates as XHTML.
PHPitfalls: Five Beginner Mistakes to Avoid
Oct 18th
Mistakes. Everybody makes them. Daryl L. L. Houston points out several common beginner blunders and how to get past them.
...excerpt from: http://www.digital-web.com/articles/phpitfalls/
Just testing out blogging from FeedDemon into WordPress. It appears I'll have to edit the PHP code to add the blockquote part though.
More PHP editing.
Oct 14th
Over to your right, you will see a randomly selected item from either Sara's Amazon Wishlist, or mine. While I got the initial script from Two Ells, I modified it to randomly select Sara's wishlist or mine, as it initally did just one wishlist.
Basically I modified the original code:
-
$aw_wishlist_id=' '; //The id of the wish list you wish to search. Hint: Search for (don't simply go to) your wish list and copy the id from the end of the URL.
with the following:
-
if ($list_to_use == 1) {
-
$aw_wishlist_id=' '; //The id of the first wish list you wish to search. Hint: Search for (don't simply go to) your wish list and copy the id from the end of the URL.
-
}
-
else {
-
$aw_wishlist_id=' '; //The id of the second wish list you wish to search. Hint: Search for (don't simply go to) your wish list and copy the id from the end of the URL.
-
// replace above with
-
// else if ($list_to_use == next number) if using more then two wishlists & modify from there.
-
}
I then had to replace:
-
$aw_header = 'Amazon Wish List'; //Used to label the box.
with:
-
if ($list_to_use == 1) {
-
$aw_header = '1st names Amazon Wish List'; //Used to label the box.
-
}
-
else {
-
$aw_header = '2nd names Amazon Wish List'; //Used to label the box.
-
}
As the original is under GNU licence obviously the above modifications are as well, feel free to add them to your Amazon Wishlist plugin if you wish (in the unlikely even that anyone visiting is actually using WordPress and the Amazon Wishlist plugin).
Update: I am using the PHPizer plugin now as well from the same site to add color to the code. Also, it seems somebody did come here to get information on it.
Update 2: It seems WordPress changes the apostrophe (') to a single quote mark in the above code listings. If you are going to use the code, you will need to replace the single quote marks with apostrophes.
Family History Page updated
Sep 28th
On the family history page, I made my second PHP program, it is the Support This Site block to the side. I actually had to modify a few other php files to make it work.
Other addition and minor changes were made to the family history itself.
Sara wins, Ari rolls, and I program
Jul 18th
Sara won, something, we are not sure what, on the Rollye James show, a national radio show. She had to answer what TV show theme song made it onto the Billboard Hot 40 chart at number one. There were four answers, and three were already down, she and another person called in at the same time with the answer, The Heights.
Ari is rolling over more, still not to the point where it seems to be on purpose yet. Sara's tried a couple of times to give him rice cereal, but he hasn't got that down yet, too much tongue. At his visit last week he weighed in at 15lbs 6oz and 25 inches long. It looks like his eye infection is over, and his tear duct may be open as well.
My first PHP program is here. I hope to learn PHP along with my C++ efforts. In regards to C++, I went back a couple of chapters to re-read a few things as it has been a while since I worked on it.






Recent Comments