Dylan Hildenbrand – Page 8 – closingtags </>
Categories
PHP

Simple PHP User Input Sort

I’ve been doing more programming challenges, and thought I would post my results here again. The first one, sorts user input. So if a user inputs a series of integers, they’ll be echoed out in order. It also does strings. The  sort is taking place with the PHP sort() function.
The second challenge was to write out the ’99 bottles of beer on the wall’ song. Both really simple challenges, but I thought it wouldn’t hurt to post them here anyways.
Sort
https://www.reddit.com/r/dailyprogrammer/comments/pu1rf/2172012_challenge_9_easy/
And here are my results:
<!DOCTYPE html>
<html>
<head>
<style>
.content {
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<div class=”content”>
<form action=”sort.php” method=”post” >
<label for=”inputs”>#’s: </label>
<input type=”text” name=”text1″ id=”text1″><br><br>
<input type=”submit” name=”submit” value=”Submit”>
</form>
<?php
if(!empty($_POST[“text1″])) {
$ints = explode(” “, $_POST[“text1”]);
sort($ints);
foreach ($ints as $key => $value) {
echo $value . “<br>”;
}
}
?>
</div>
</body>
<footer>
</footer>
</html>

99 bottles
https://www.reddit.com/r/dailyprogrammer/comments/pserp/2162012_challenge_8_easy/

With the solution here:
<!DOCTYPE html>
<html>
<head>
<style>
.content {
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<div class=”content”>
<?php
$bottles = 99;
while ($bottles > 1) {
echo $bottles . ” bottles of beer on the wall, ” . $bottles . ” bottles of beer, take one down and pass it around ” . –$bottles .” bottles of beer on the wall. “;
}
echo $bottles . ” bottle of beer on the wall, ” . $bottles . ” bottle of beer, take one down and pass it around ” . –$bottles .” bottles of beer on the wall. “;
?>
</div>
</body>
<footer>
</footer>
</html>

 

Categories
PHP

Random Password Generator

I’ve had a little bit of downtime at work, and didn’t want to be idle. Luckily for me, I found this awesome subreddit, called /r/dailyprogrammer. They’ve got tons of programming challenges for a wide variety of skills. So I’ve been picking through some simple ones in my down time, and doing some of the easier ones. This one is the most recent challenge I did.
Basically, it just asks you to create a random password generator (like this one) with the ability to specify how many passwords to generate, and how long the string should be. And since the comments are closed, I can’t really submit my solution there, so here is what I came up with, in PHP.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style=”text-align: center; margin: 50px;”>
<form action=”passwords.php” method=”post” style=”margin-bottom: 25px;” enctype=”multipart/form-data”>
<label for=”inputs”># of passwords: </label>
<input type=”text” name=”text1″ id=”text1″><br><br>
<label for=”inputs”>string length: </label>
<input type=”text” name=”text2″ id=”text2″><br><br>
<input type=”submit” name=”submit” value=”Submit”>
</form>
<?php
if($_POST[“text1”] && $_POST[“text2”]) {

$max = intval($_POST[“text1”]);
$length = intval($_POST[“text2”]);
$count = 0;

$seed = str_split(“abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_”, 1);

$tehstring = “”;

while($count < $max) {
for ($i=0; $i < $length; $i++) {
$tehstring .= $seed[mt_rand(0, count($seed)-1)];
}

echo $tehstring . “<br>”;
$tehstring =””;
$count++;
}
}
?>
</div>
</body>
<footer>
</footer>
</html>

 

Categories
HTML5 jQuery

HTML Games

Whoa. I just discovered this super easy way to build HTML5 web games, where a ton of the heavy lifting is already done for you. Seriously, go check out what the guys and gals over at Photon Storm are doing and check out Phaser

Categories
CSS Themes WordPress

Custom WordPress Admin Login Logo

If you want to replace the WordPress logo on your admin login page with your own custom image, you can do it with just a couple simple lines in your functions.php file.
add_action(“login_head”, “my_login_head”);
function my_login_head() {
echo “<style>
body.login #login h1 a {
background: url(‘”.get_bloginfo(‘template_url’).”/images/logo_login.png’) no-repeat scroll center top transparent;
height: 181px;
width: 269px;
padding:0 25px;
}
</style>”;
}
Simply upload your file to the proper path and adjust the CSS accordingly.

Categories
CSS Themes WordPress

Shortcodes for Custom Column Sizes

WordPress is great, but sometimes, when you’re writing a blog post, the WSIWYG is just lacking certain features. Say you want to format your content and make things a little cleaner. Like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel urna ut elit faucibus semper. Morbi dignissim ex enim, et consectetur justo blandit vel. Etiam lobortis nulla vel tellus dictum dignissim. Fusce purus lectus, luctus vitae imperdiet ac, lobortis quis urna. Integer id venenatis quam. Cras ac neque sit amet urna consequat pellentesque.

Nunc vitae laoreet purus. Ut egestas, metus eget accumsan fringilla, erat justo congue tellus, pulvinar vehicula nunc enim nec augue. Praesent gravida blandit risus dapibus pharetra. Proin consequat et nisl quis tincidunt. Proin at massa odio. Cras malesuada porta ultricies. Fusce tristique blandit leo at tempus. Curabitur tincidunt ex quis lacus sodales ornare.

By the way, you can get copy/paste lorem ipsum from http://www.lipsum.com/feed/html
Well, if this is something you’d like to be able to do, you can make a couple quick edits in functions.php and style.css of your theme. The CSS code looks like this:
/*
* Fluid Columns
* —————————————————————————-
*/
.one_half{ width:48%; }
.one_third{ width:30.66%; }
.two_third{ width:65.33%; }
.one_fourth{ width:22%; }
.three_fourth{ width:74%; }
.one_fifth{ width:16.8%; }
.two_fifth{ width:37.6%; }
.three_fifth{ width:58.4%; }
.four_fifth{ width:79.2%; }
.one_sixth{ width:13.33%; }
.five_sixth{ width:82.67%; }
.one_half,.one_third,.two_third,.three_fourth,.one_fourth,.one_fifth,.two_fifth,.three_fifth,.four_fifth,.one_sixth,.five_sixth{ position:relative; margin-right:2%; padding-right:2%; float:left; }
.last{ margin-right:0 !important; padding-right:0 !important; clear:right; }
.clearboth {clear:both;display:block;font-size:0;height:0;line-height:0;width:100%;}

And this is what you will put in the functions.php:
function columns_one_third( $atts, $content = null ) { return ‘<div class=”one_third”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_third’, ‘columns_one_third’);
function columns_one_third_last( $atts, $content = null ) { return ‘<div class=”one_third last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_third_last’, ‘columns_one_third_last’);
function columns_two_third( $atts, $content = null ) { return ‘<div class=”two_third”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘two_third’, ‘columns_two_third’);
function columns_two_third_last( $atts, $content = null ) { return ‘<div class=”two_third last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘two_third_last’, ‘columns_two_third_last’);
function columns_one_half( $atts, $content = null ) { return ‘<div class=”one_half”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_half’, ‘columns_one_half’);
function columns_one_half_last( $atts, $content = null ) { return ‘<div class=”one_half last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_half_last’, ‘columns_one_half_last’);
function columns_one_fourth( $atts, $content = null ) { return ‘<div class=”one_fourth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_fourth’, ‘columns_one_fourth’);
function columns_one_fourth_last( $atts, $content = null ) { return ‘<div class=”one_fourth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_fourth_last’, ‘columns_one_fourth_last’);
function columns_three_fourth( $atts, $content = null ) { return ‘<div class=”three_fourth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘three_fourth’, ‘columns_three_fourth’);
function columns_three_fourth_last( $atts, $content = null ) { return ‘<div class=”three_fourth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘three_fourth_last’, ‘columns_three_fourth_last’);
function columns_one_fifth( $atts, $content = null ) { return ‘<div class=”one_fifth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_fifth’, ‘columns_one_fifth’);
function columns_one_fifth_last( $atts, $content = null ) { return ‘<div class=”one_fifth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_fifth_last’, ‘columns_one_fifth_last’);
function columns_two_fifth( $atts, $content = null ) { return ‘<div class=”two_fifth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘two_fifth’, ‘columns_two_fifth’);
function columns_two_fifth_last( $atts, $content = null ) { return ‘<div class=”two_fifth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘two_fifth_last’, ‘columns_two_fifth_last’);
function columns_three_fifth( $atts, $content = null ) { return ‘<div class=”three_fifth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘three_fifth’, ‘columns_three_fifth’);
function columns_three_fifth_last( $atts, $content = null ) { return ‘<div class=”three_fifth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘three_fifth_last’, ‘columns_three_fifth_last’);
function columns_four_fifth( $atts, $content = null ) { return ‘<div class=”four_fifth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘four_fifth’, ‘columns_four_fifth’);
function columns_four_fifth_last( $atts, $content = null ) { return ‘<div class=”four_fifth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘four_fifth_last’, ‘columns_four_fifth_last’);
function columns_one_sixth( $atts, $content = null ) { return ‘<div class=”one_sixth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘one_sixth’, ‘columns_one_sixth’);
function columns_one_sixth_last( $atts, $content = null ) { return ‘<div class=”one_sixth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘one_sixth_last’, ‘columns_one_sixth_last’);
function columns_five_sixth( $atts, $content = null ) { return ‘<div class=”five_sixth”>’ . do_shortcode($content) . ‘</div>’; } add_shortcode(‘five_sixth’, ‘columns_five_sixth’);
function columns_five_sixth_last( $atts, $content = null ) { return ‘<div class=”five_sixth last”>’ . do_shortcode($content) . ‘</div><div class=”clearboth”></div>’; } add_shortcode(‘five_sixth_last’, ‘columns_five_sixth_last’);

function columns_formatter($content) {
$new_content = ”;

/* Matches the contents and the open and closing tags */
$pattern_full = ‘{(\[raw\].*?\[/raw\])}is’;

/* Matches just the contents */
$pattern_contents = ‘{\[raw\](.*?)\[/raw\]}is’;

/* Divide content into pieces */
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

/* Loop over pieces */
foreach ($pieces as $piece) {
/* Look for presence of the shortcode */
if (preg_match($pattern_contents, $piece, $matches)) {

/* Append to content (no formatting) */
$new_content .= $matches[1];
} else {

/* Format and append to content */
$new_content .= wptexturize(wpautop($piece));
}
}

return $new_content;
}

// Remove the 2 main auto-formatters
remove_filter(‘the_content’, ‘wpautop’);
remove_filter(‘the_content’, ‘wptexturize’);

// Before displaying for viewing, apply this function
add_filter(‘the_content’, ‘columns_formatter’, 99);
add_filter(‘widget_text’, ‘columns_formatter’, 99);

Now to use this handy feature, you basically say:

Your content goes here…..

Your content goes here…..

If you wanted three columns, you’d replace ‘one_half’ with ‘one_third’, four columns, you’d replace ‘one_half’ with ‘one_fourth, and so on. Just make sure your last column has the ‘_last’ appended to both opening and closing tags.
Mobile
This is a pretty great feature, but it does break down on mobile devices. So in the media queries of the theme, I find it best to simple break the columns, and set each section to full width. The .clearboth class in the CSS code has pretty much everything you need (but also some extra) so we’ll take a piece out of that and do this in our media queries.
@media screen and (max-width: 758px) {

.one_half,.one_third,.two_third,.three_fourth,.one_fourth,.one_fifth,.two_fifth,.three_fifth,.four_fifth,.one_sixth,.five_sixth {
clear:both;
display:block;
width:100%;
}
}
This way, when the device screen gets to a smaller size, your columns will break into full width divs.
Source

Categories
Themes WordPress

Disabling Comments In WordPress

Sometimes, WordPress is used for websites that are not blogs. And sometimes, those websites don’t want to hear back from people on the internet, because; let’s face it, people on the internet can suck. So if you want to make sure those sucky people don’t comment on your site, don’t try and delete the wp_comments table from the WordPress database like this guy thought he could do. That’s just going to cause problems. Instead, try this code.
// Disable support for comments and trackbacks in post types
function df_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, ‘comments’)) {
remove_post_type_support($post_type, ‘comments’);
remove_post_type_support($post_type, ‘trackbacks’);
}
}
}
add_action(‘admin_init’, ‘df_disable_comments_post_types_support’);

// Close comments on the front-end
function df_disable_comments_status() {
return false;
}
add_filter(‘comments_open’, ‘df_disable_comments_status’, 20, 2);
add_filter(‘pings_open’, ‘df_disable_comments_status’, 20, 2);

// Hide existing comments
function df_disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;
}
add_filter(‘comments_array’, ‘df_disable_comments_hide_existing_comments’, 10, 2);

// Remove comments page in menu
function df_disable_comments_admin_menu() {
remove_menu_page(‘edit-comments.php’);
}
add_action(‘admin_menu’, ‘df_disable_comments_admin_menu’);

// Redirect any user trying to access comments page
function df_disable_comments_admin_menu_redirect() {
global $pagenow;
if ($pagenow === ‘edit-comments.php’) {
wp_redirect(admin_url()); exit;
}
}
add_action(‘admin_init’, ‘df_disable_comments_admin_menu_redirect’);

// Remove comments metabox from dashboard
function df_disable_comments_dashboard() {
remove_meta_box(‘dashboard_recent_comments’, ‘dashboard’, ‘normal’);
}
add_action(‘admin_init’, ‘df_disable_comments_dashboard’);

// Remove comments links from admin bar
function df_disable_comments_admin_bar() {
if (is_admin_bar_showing()) {
remove_action(‘admin_bar_menu’, ‘wp_admin_bar_comments_menu’, 60);
}
}
add_action(‘init’, ‘df_disable_comments_admin_bar’);
Just take the code snippets you want from this, and drop them into the theme’s functions.php file to disable comments site wide.
 

Categories
Plugins Themes WordPress

Custom Admin Toolbar in WordPress

I spend a lot of time on StackOverflow, as most people in any programming field do. Well, when I get time, I like to try and answer questions to give back to the community. Sometimes, I can be helpful. Not always, but sometimes.
Yesterday was one of those days. A question came up, about creating a custom interface with the WordPress admin bar. Seeing as how I’d never tried this, I thought I’d give it a shot and figure it out.

After being sidetracked by actual work, I finally got to work on the question and came up with a solution.
add_action(‘wp_before_admin_bar_render’, ‘change_admin_bar’,999);

function change_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->remove_node(‘edit’)

$args = array(
‘id’ => ‘edit’,
‘title’ => ‘Edit Backend’,
‘href’ => get_edit_post_link(),
);

$wp_admin_bar->add_node($args);
}
This code, when placed in the functions.php file of your theme, will remove the ‘Edit Post’ button from the admin bar, and then replace it with a button labeled ‘Edit Backend.’ It’s a super simple piece of code and there’s tons more that can be done with this kind of thing. You can tweak your admin toolbar to your heart’s content.
If you’re looking to do more than this, you can always go to the Codex to get more info or here.
Oh! And this is the link to Stack Overflow thread.

I don’t get to be useful on that website too often as there are so many brilliant minds, it’s easy to get cluttered.

Categories
jQuery

Code School

I know it’s been a while since I’ve written anything here and I really don’t have any excuse other than I got lazy. But this is a short, quality post that I’m writing on my phone while my wife is shopping. How cool is that?
Anyways, if you click this link, you can get two free days of Code School. That’s right. Free. They have excellent courses on jQuery, Ruby, Git, and a lot of other developer tools. So check it out.

Categories
CSS

Styling Scrollbars w/CSS

I came across this post while searching for a means of styling some scrollbars on a site I was working on recently. It seems, that styling the scrollbar specifically, ins’t a problem in certain browsers. Some though (Firefox and Opera) are a pain. I’ll cover those another time. For now, let’s just get Chrome and IE taken care of.
Internet Explorer
This is the CSS that you can apply to a particular element for Internet Explorer. Surprisingly, this should work with most versions of IE.
body{
scrollbar-base-color: #C0C0C0;
scrollbar-base-color: #C0C0C0;
scrollbar-3dlight-color: #C0C0C0;
scrollbar-highlight-color: #C0C0C0;
scrollbar-track-color: #EBEBEB;
scrollbar-arrow-color: black;
scrollbar-shadow-color: #C0C0C0;
scrollbar-dark-shadow-color: #C0C0C0;
}
And these are what each style is affecting:

Chrome (Webkit Browsers)
Now, those styles won’t carry over to Chrome. If you want to do that, you can use these pseudo elements:
::-webkit-scrollbar { width: 3px; height: 3px;}
::-webkit-scrollbar-button { background-color: #666; }
::-webkit-scrollbar-track { background-color: #999;}
::-webkit-scrollbar-track-piece { background-color: #ffffff;}
::-webkit-scrollbar-thumb { height: 50px; background-color: #666; border-radius: 3px;}
::-webkit-scrollbar-corner { background-color: #999;}}
::-webkit-resizer { background-color: #666;}
Those elements affect the scrollbars in like so:

Again, this information came from this blog. I’m simply re-hosting this information for the sake of sharing information. But if you’d like to buy me a beer, feel free.

Categories
CSS

Getting SASS to work with Sublime Text 2

This tutorial is essentially just going to be the same as this one so you can go read it there if you’d rather. I promise, I won’t be offended. After all, this is the tutorial I used.
Basically, you’ve got SASS installed and ready to go after reading this post. Now, you want to use it with Sublime Text 2 so everything is super easy.
First things, first. Open package control, and install ‘SASS’
Once you install that plugin, you’ll notice SCSS files look fine, but SASS files aren’t color-coded. You’re going to want to open a SASS file, click ‘View’, ‘Syntax’, and then ‘Open all w/current extension as -> SASS’.
Then install the SASS build plugin for Sublime. This plugin activates the keyboard shortcut ‘CTRL + B’ for building which is fine, but you’ll want to install the Sublime Save On Build plugin to make things even simpler. Basically, every time you save your files, it’ll handle everything you need it to and update your CSS so you can move it to your server.