Dynamically change url or WordPress theme if UserAgent is iPhone - php

Is there any way to do this?
My website is http://kennethreitz.com. Its driven by some moderate PHP on top Wordpress.
My options are to detect if the user is using an iphone, and if they are either
a) tell wordpress to load a different "theme" that i have written.
b) if this isn't possible, have a different wordpress installation on a subdomain (i.kennethreitz.com) that operates out of the same database, that uses a different theme.
I'd rather be able to do A for SEO reasons.
Any ideas?

http://www.nathanrice.net/blog/serve-ie6-visitors-the-default-wordpress-theme/ demonstrates how to use template filter to dynamically change the WordPress theme (in this case IE6, but it could be for a mobile user agent):
add_filter('template', 'serve_default_to_iesix');
add_filter('option_template', 'serve_default_to_iesix');
add_filter('option_stylesheet', 'serve_default_to_iesix');
function serve_default_to_iesix($theme) {
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false)
$theme = 'default';
return $theme;
}

Have you looked at iWPhone?
It's a Wordpress plugin and theme that automatically takes care of detecting whether the visitor is from an iPhone and formats things appropriately. Pretty easy to substitute your own custom iPhone CSS if you want, although the basic theme is pretty decent.
There's also WPTouch which looks to be similar in functionality but is a bit more recent and has better administration integration.

Here is a Wordpress plugin which serves different themes to different browsers (e.g. iPhone):
http://code.kuederle.com/browserbasedthemes

I don't have experience with WordPress, but the iWPhone plugin + theme looks like it might work

Out of the box you cannot do either A or B.
Loading a different theme is not possible as that option is stored in the database under the wp_Options table. This setting is site wide not per user. Option B is not an option either since you would be sharing the same database you would be selecting the same value for the theme.
If you look in the wp_options table the theme setting will be found in the record that corresponds to "template" and "stylesheet".

Related

Two wordpress sites using diiferent themes on the same database

I want to run 2 wordpress sites, one.site.com and two.site.com from the same database. Everything remains the same except for the theme.
one.site.com - Existing site
two.site.com - Should use one.site.com's database except for the
theme
Is there any way this can be done ?
Since theme details are stored in wp_options table is it possible for two.site.com to use it to display a different theme ? Say duplicating that table and making two.site.com use it ?
I appreciate any help.
EDIT:
Both the sites do not have any plugins.
The solution below did the job for me,
Install 2 WordPress sites on a single database.
Create new table in your database. Call it wp_options2 and copy everything from wp_options into this new table
In second install go to wp-config.php, and before if (!defined('ABSPATH')) add define( 'M7_OPTIONS_TABLE', 'wp_options2');
In second install go to wp-includes/wp-db.php on line 1009 and add code:
if (isset( $tables['options'] ) && defined('M7_OPTIONS_TABLE')) $tables['options'] = M7_OPTIONS_TABLE;
These codes should be added in public function tables function, before if (isset( $tables['users']) && defined('CUSTOM_USER_TABLE')))
I found this solution here, https://wordpress.stackexchange.com/questions/84313/how-to-run-two-wordpress-blogs-with-different-themes-and-with-single-database-an#answer-175494
Since we use the same database, links will be same on both the sites. I had a lot of images linked and I removed them using
.single a[href$=".jpg"] {
pointer-events: none;
cursor: default;
}
You can run two sites from a single database but not from the same set of database tables as the stored data includes the site's domain name.
There are two values in the options table: siteurl and home which are used. Using the same options table won't work, even if you update options forcefully for each php run.
So you would need to use two databases.
EDIT:
My advice is to replicate base and run both sites on different databases.
This could probably be accomplished by using wildcard subdomains (https://codex.wordpress.org/Configuring_Wildcard_Subdomains).
It may be a little hacky, but you'd have to test the condition of your subdomain (maybe in wp-config.php?) and set the theme in the database (http://www.inmotionhosting.com/support/edu/wordpress/change-theme-in-db).
The only problem I could see with this is that your functions.php can change WP functionality, so a Parent theme with two Child Themes is probably a good idea(https://codex.wordpress.org/Child_Themes).
There is a lot of jiggery hackery regarding this question, but I think there's a fairly simple solution. First, ensure that both of your 2 sites have these hardcoded in wp-config.php:
define('WP_HOME', 'https://example.com');
define('WP_SITEURL', 'https://example.com');
These will help each site "override" whatever the database setting is for the URLs.
Next, decide which site is the MASTER site where you are going to be publishing new blog posts, making edits to site data, and such. On that site, activate the theme you want to use.
Now, go to your SLAVE site (I'm using these terms loosely) and delete that theme via SFTP, and upload whichever other theme you want to use on that site. Then, hardcode it like this:
define('WP_DEFAULT_THEME', 'twentytwenty');
In this way, the SLAVE site tries to find the correct theme from wp_options that is activated on the MASTER site but you deleted it already, so it reverts to using the default theme as defined in wp-config.php
Going forward, do not mess with site settings/plugins/etc on the SLAVE site, and make any changes to the design of your SLAVE site using the theme files only (like a static theme). Obviously if you are using a bloated theme and page builder type of situation that need MySQL, this isn't going to work...
Note: you may need to visit /wp-admin/themes.php on your SLAVE site at least once, to "force" WordPress to load the hardcoded theme.
If anyone is interested, SlickStack supports this approach.
Duplicate of https://wordpress.stackexchange.com/q/65560/wp-multisite-load-content-from-site-x-on-site-y
One might argue that using WP multisite-network functionality and adding a couple of documented API calls to ones theme could be a cleaner solution than manually modifying the database schema and messing with how WP access it.

Is there ability to deploy a wordpress page/pages inside of another engine site

Apprecaite any help on my question.
Lets pretend, I have a internet shop driven on joomla or some another engine. Can i make a part of it on wordpress, for example, the page for every item in the shop? Dont take a look to the oddness of situation :) just want to know is there ability to cross engines. Also, if you can, please recommend manuals.
Have a nice day!
Yes, you can as exhibited in this WordPress Codex page but you will not be able to take advantage of the WordPress URL routing scheme, WordPress themes, plugins or widgets -- not directly -- you'll have to write custom code to use them.
<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>
You will just have access to the WordPress functions with which you will be able to fetch posts from the DB and then you will be able to write custom PHP code to display those posts.
Obviously displaying plugins or widgets will also become your responsibility -- you'll have to call functions which either render all plugins or fetch a list of plugins/widgets and decide what to do with them.

Wordpress Development

I have one project of blog site to be developed in wordpress. I have no experience how wordpress works, I read Codex documentation, But didn't find the answer of my questions,
So Project Requirements are ,
1: Post Movie with Thumbnails,Links to Download or Streaming Websites,Genre(Taxonomy),Youtube Movie Trail,
2: User can Like,rate,comment,Add to watch list,Share with friends
3: I have database of more than 3000 Records, I don't want to insert it to the wp_posts Table for some reasons.
4: How to add javascript to Widgets,or Plugin (Maybe it's a stupid Question)
My problem is I don't know what is the write way to do it. There are Two Major things in WP
1: Plugin
2: Widgets
How can i use them in my project ? From Where Should I start First, I have done with the theme Development, And Some Basic Concepts of wordpress Like, Action,Filters. I can create this project easily with the PHP and JS . Don't suggest me any premade wordpress plugin or Widgets, I want to code it myself
What do you mean add javascript to widgets or plugins? You can include javascript by adding it to the Theme of the page.
Most of your development should be on a Theme. A Theme is essentially a collection of different page templates, styling and functions that will be used. Theme can also handle taxonomy and meta data.
Since you have a DB already what you could do is make a page template called "movie" that pulls an ID/Slug and retrieves it from the database to get the relevant information.
Helpful Links:
Taxonomy - http://codex.wordpress.org/Taxonomies
Queuing Scripts - http://codex.wordpress.org/Function_Reference/wp_enqueue_script
WPDB (Database Class) - http://codex.wordpress.org/Class_Reference/wpdb
I think there might be already some themes ready with the functionalities you want. Did you do a search for stock themes? I've come across a few for video/movies displaying with ratings, social sharing, etc. So your development work would reduce significantly.

Can I use Wordpress just for the CMS UI, and pull using an API/raw SQL? (How?)

I have a small project for which I need to offer a CMS UI/storage system.
I am guessing that I can have my computer-fearing client use the Wordpress UI to store a set of images for her gallery page, and a set of text for her testimonials page. And then, through a Wordpress function, or raw SQL query into the database, I can get the data that I need on the page.
If this is possible, how do I do this?
We use the Pods CMS Wordpress plugin to help us create custom data fields for our site, for areas where the typical post/page structure just isn't appropriate.
Like everything else in Wordpress, Pods is a little rough around the edges, but it does provide a fairly simplistic interface for pulling information out of a database, without the need for raw SQL, or bolting together custom fields for a post.
A simple example for looping over records might look like:
$mypod = new Pod('mypod');
$mypod->findRecords('date ASC', 15) // ORDER BY date ASC, LIMIT 15
while ($mypod->fetchRecord()) {
$image = $mypod->get_field('image')
...
}
It also supports a basic set of relationships between Pod objects.
You can either just create your own theme/template for Wordpress, or you can create your own frontend altogether with raw SQL queries. The database layout is rather simple so it shouldn't be impossible to create your own system.
But consider the theme solution first because I think it's both easier for you (not needing to reinvent the wheel) and better for security (easy to use the built-in functionality for security updates).
So, WordPress 3.0 is getting to the point where it is no longer just a blogging platform, but almost a fullblown CMS. For her testimonial pages, or about me, contact, etc, you can use WordPress. Instead of creating new entries, just have her (or you) create pages.
For the gallery, there is an open source project called Gallery that you can use that would allow the client to upload and manage their own photos. In WordPress, just create a new menu item and link to the Gallery installation you have.

Wordpress Digg-Like Voting System Plugin

I just found out about BuddyPress (a collection of plugins that convert a WordPress MU install into a social network) and now I was wondering if there are any Digg-like voting plugins for WordPress. This would eventually integrate into a BuddyPress website, where the site members would submit, vote and comment on stories (much like Digg).
I have a feeling I will end up having to build this from scratch, but since the site will be built on WordPress, I was wondering if there were any plugins already available that add this functionality. So far I have come up empty in my search. I did find a Wordpress blog that had this functionality WpVote. It even creates thumbnails of the story webpage automatically (I'm assuming) using websnapr. I browsed through the page source and didn't seem to find any hints of a WP plugin that they are using.
I've successfully used TDO Mini Forms for user submissions combined with Vote it up to build a digg-style site.
You can create a "top votes" page using the MostVotedAllTime_Widget() function from Vote it up, or use the SortVotes() or GetVoteArray() functions to build and style your own top votes list in a customised page template.
You'll find the full list of available functions in /vote-it-up/votingfunctions.php
BuddyPress Links is what you're looking for:
http://wordpress.org/extend/plugins/buddypress-links/
Or you can try:
Pligg Voting CMS
when i was start to build my own social bookmarking, i using voteitup plugin but if you want to build your own vote button you can visit bavotasan.com and search post "simple-voting for-wordpress-with-php-and-jquery"
take a look at my own social bookmarking using it : http://nestdev.com
http://prothemedesign.com/themes/nominate-for-wordpress/
is a premium theme I've come across but never used. It's a WP version of Digg and I believe pretty good.
Personally I use Drigg which is a Drupal version of Digg. See it in action here: http://weblinks.myfriendshotel.com Unfortunately, however, WebSnapr have just changed their code so the site is no longer showing thumbanails but hopefully as a 'non-programmer' I'll find a solution soon...
Is this what you're after?
http://www.tevine.com/projects/voteitup/
I think [wpvote][1] use drigg module for drupal. I've just found buddypress plugin which has similiar function like digg social bookmarking. more detail
Not sure if this is still relevant or not but the theme used for WPVote.com has now been released on Pro Theme Design - http://prothemedesign.com/themes/nominate-for-wordpress/

Categories