WordPress Goodies
A few tidbits for WordPress I picked up this week working on Psychic Coupons and a couple other sites.
===============================================
This is an oldie but goody, helps a lot: http://codex.wordpress.org/Template_Hierarchy
and the PNG: http://codex.wordpress.org/images/1/18/Template_Hierarchy.png
===============================================
Here’s one from equalmark and banago at http://wordpress.org/support/topic/query-if-on-front-page-home-index :
If you’re on the front page, conditional statements:
<?php if(is_front_page() ) { ?> //do stuff <?php } ?>
— or --
<?php if(is_home() ) { //do stuff } else { //do stuff } ?>
Mvied notes: I’d just like to point out that the is_home() function is true if you’re on the main blog page, and the is_front_page() function can be the same page unless you have a static front page set, then it will only be true on that page.
============================================
Passing variables in the URL, by stvwlf from http://wordpress.org/support/topic/passing-variables-using-the-permalink-structure :
Step 1: Create and save PHP file in plugins directory: <?php /* Plugin Name: Parameter Plugin URI: http://webopius.com/ Description: A plugin to allow parameters to be passed in the URL and recognized by WordPress Author: Adam Boyse Version: 1.0 Author URI: http://www.webopius.com/ */ add_filter('query_vars', 'parameter_queryvars' ); function parameter_queryvars( $qvars ) { $qvars[] = ' myvar'; return $qvars; } ?>
Step 2: Pass var in URL href: if (isset($wp_query->query_vars['myvar'])) { print $wp_query->query_vars['myvar']; }
=============================================
Find and show related posts by tag: http://wordpress.org/support/topic/variables-through-get_posts-query_posts
=============================================
elseloop offers a simple way to implement a “Post template based on category”: http://wordpress.org/support/topic/post-template-based-on-category-or-tag
=============================================
I just want to pass my thanks to the many talented people who take the time to share their expertise on the WordPress community forum. They are adding value to the world, so, KUDOS to all you geniuses!
Posted under WebDev, WordPress
This post was written by Content Curator on April 10, 2012
How to Grab All Text After The Last Occurence Using Excel
In a Microsoft Excel spreadsheet cell one can use a custom function to effectively grab all test after the final (last) occurrence of a particular character or string. This is accomplished by simply creating a Custom Function and then using that function in a cell formula. Following is the code and instructions for how to create and then implement the function.
Function PullAfterLast(rCell As Range, strLast As String)
PullAfterLast = Mid(rCell, InStrRev(rCell, strLast) + 1, 256)
End Function
- Highlight the above code, and copy it to the clipboard by pressing CTRL-C, or by right-clicking on the text and on the resulting popup window left-clicking on Copy.
- Open Microsoft Excel (or proceed to step 2 if you prefer to open Excel by clicking the desired existing .xls file directly.).
- Open the workbook you wish to use the function with, or create a new workbook.
- Open the Visual Basic Editor window by pressing ALT-F11 on the keyboard, or clicking Tools > Macros > Visual Basic Editor
- Insert a new module by right-clicking on ThisWorkbook > Insert > Module or on the toolbar clicking Insert > Module
- Paste the clipboard contents (which is the code above this numbered procedure) into the code window by pressing CTRL-V, or by right-clicking in the code window and on the popup menu clicking on Paste, or by clicking the menu toolbar on Edit and clicking on Paste.
- Close the Visual Basic Editor by presing CTRL-Q, or by clicking File on the menu toolbar and then clicking Close and Return to Microsoft Excel.
The custom user defined function is now available to be used in the formulas of cells. To use it, the following syntax format is used in the cell’s formula:
=PullAfterLast(A1,"yourstring")
Of course, replace yourstring with the appropriate character or string.
This info was combined from ozgrid.com article about how to make custom functions easily, and vertex42.com article where Dave Hawley gave the universe this function’s code, many thanks!
Posted under Excel, Microsoft, Office
This post was written by Content Curator on November 19, 2009
How to Add Thumbnails in WordPress
When a website user makes a search with WordPress, the search results typically are shown using the search.php template file. If one chooses to do so, these results can incluse an automatically “grabbed” image thumbnail generated by the images contained in the image. Posts with no images can show a default generic image instead. And this can all be done using the Get-The-Image plugin and perhaps a bit of code tweaking.
<div style="clear: both; margin-bottom: 20px;">
<div style="float: left; width: 150px; height: 150px; margin: 0 10px 10px 0;"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php if ( function_exists( 'get_the_image' ) ) { get_the_image('width=150&height=150&image_scan=true&default_image=http://yoursite.com/default.jpg' ); } ?></a></div>
<div>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php the_time('F jS, Y') ?> by <?php the_author_posts_link(); ?><br />
<p>Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
</div>
Insert this snippet, written by mercime ar wordpress.org into your loop, typically right after the beginning while-have-posts loop.
Posted under WebDev, WordPress
This post was written by Content Curator on November 16, 2009
How to Select First Last or Range of Records in MySQL Table
When using MySQL, and wanting to retrieve the first n records from a table, one can use the LIMIT function. It can also be used to grab a range of records, not just a series starting with the first record. Use as follows:
SELECT * FROM yourtable LIMIT yourlowlimit,yourhighlimit;
This will return all rows between the number yourlowlimit and yourhighlimit inclusive.
e.g. SELECT FROM users LIMIT 20,50
will return the rows 20, 21, 22,…, 49, 50
This post was written by Content Curator on November 16, 2009
How to automatically reload a page when it is finished reloading, using javascript
So, you have a web page (HTML, PHP, etc.) that you want to reload over and over. And at the same time, you want to be sure that the entire page loads before it starts the loop over again. Here is a javascript way to do just that. Simply include this script in yout HTML code, and watch the magic:
<script language="javascript"> window.onload=new Function("window.location.reload();"); </script>
Enjoy!
Posted under WebDev
This post was written by Content Curator on October 3, 2008