Two questions from a coding ub3r n00b...
Firstly, I'm using the Options Framework Theme by Devin Price and just wanting to know how would I output the background property in the <head> section of my header.php file, from the Theme Options page only if the user has uploaded an image or chosen a color for this?
My options.php:
$options[] = array(
'name' => __('Background', 'options_framework_theme'),
'desc' => __('Add a background.', 'options_framework_theme'),
'id' => 'background-one',
'std' => $background_defaults,
'type' => 'background' );
My Theme Options page:
My header.php:
<style type="text/css">
<?php $background = of_get_option('background-one');
echo 'body {';
if ($background['color']) {
echo '
background: ' .$background['color']. ';';
}
if ($background['image']) {
echo '
background: url('.$background['image']. ') ';
echo ''.$background['repeat']. ' ';
echo ''.$background['position']. ' ';
echo ''.$background['attachment']. ';';
}
echo '
}';
?>
</style>
Which works perfectly fine in the front-end of my site, displaying the CSS as:
body {
background: #8224e3;
background: url(images/bg03.gif) repeat top left fixed;
}
But if the user hasn't chosen a colour or image as a background through the Theme Options page, the source code will output:
body {
}
How would I be able to remove the above CSS if the user hasn't chosen a background?
From what I gather, an if statement needs to be created but I don't how to write this up correctly as I'm fairly new to php.
Secondly, how would I be able to set a default background image in the framework?
My options.php:
// Background Defaults
$background_defaults = array(
'color' => '',
'image' => '',
'repeat' => 'no-repeat',
'position' => 'top left',
'attachment' => 'fixed' );
Thanks
Just move a few things to be within an if statement, like so:
<?php
$background = of_get_option('background-one');
if ($background['color'] || $background['image']) {
echo '<style type="text/css" >';
echo 'body {';
if ($background['color']) {
echo '
background: ' .$background['color']. ';';
}
if ($background['image']) {
echo '
background: url('.$background['image']. ') ';
echo ''.$background['repeat']. ' ';
echo ''.$background['position']. ' ';
echo ''.$background['attachment']. ';';
}
echo '
}';
echo '</style>';
}
?>
And, for your second question, simply make the following change:
// Set up a default image
// NOTE: This is designed for the image to be located in your theme folder, inside an images folder
$default = get_bloginfo("template_url") . 'images/default.jpg';
// Background Defaults
$background_defaults = array(
'color' => '',
'image' => $default,
'repeat' => 'no-repeat',
'position' => 'top left',
'attachment' => 'fixed' );
Related
I am trying to retrieve data from a wordpress table using a shortcode function I found. It works and retrieves the data for all the columns. When I try to specify the columns I want it still give me everything. Ultimately what I am trying to do is retrieve the data for the columns I want and style that data using css (not in a table format). I am new to php so I was wondering if anyone could let me know if this is even possible using shortcodes. If it is possible any help would be appreciated. Thank you in advance, Randy
Here is the code I am using:
if ( !defined( 'WP_FD_ABSPATH' ) )
define( 'WP_FD_ABSPATH', plugin_dir_path( __FILE__ ) );
function wp_first_shortcode($atts){
global $wpdb;
$a = shortcode_atts( array(
'table_name' => ",
'columns' => ",
), $atts );
$showcolumns=array();
if($a['columns']!=""){
$column=$a['columns'];
$showcolumns=explode(',',$a['columns']);
}
else{
$column='*';
$get_columns=$wpdb->get_results("describe ".$a['table_name']."");
foreach($get_columns as $fields) $showcolumns[]=$fields->Field;
}
$columncount=count( $showcolumns);
$result_query=$wpdb->get_results( "select $column from ".$a['table_name']."");
echo '<table><tr>';
for($i=0;$i<$columncount;$i++) echo '<th>'.$showcolumns[$i].'</th>';
echo '</tr>';
foreach($result_query as $result_row){
echo '<tr>';
for($i=0;$i<$columncount;$i++) echo '<td>'.$result_row->$showcolumns[$i].'</td>';
echo '</tr>';
}
echo '</table>';
}
add_shortcode('fetchdata', 'wp_first_shortcode');
function table_value_function() {
query_value(array('orderby' => 'date', 'order' => 'DESC' , 'showvalues' => ""));
wp_reset_query();
return $return_string;
}
?>
Here is the shortcode I am using:
[fetchdata table_name='my_wp_table' columns ='Display_Name' 'First_Name' 'Last_Name' 'Address_1' 'Address_2' 'City' 'State' 'Phone']
Ok, I think you just want to get rid of the table as you want to style it with CSS. Please follow the code below:
echo '<div class="something">';
for($i=0;$i<$columncount;$i++) echo '<h1>'.$showcolumns[$i].'</h1>';
foreach($result_query as $result_row){
echo '<div class="something_2">';
for($i=0;$i<$columncount;$i++) echo '<p>'.$result_row->$showcolumns[$i].'</p>';
echo '</div>';
}
echo '</div>';
}
Hope, it helps.
I've got a problem with my source code. I've don't used since... 8/9 months and now, it doesn't work anymore.
I'm looking to list all my photos in my albums BUT, now it's listing me just 25 photos of each album and not more. I've got 100/200/250 photos per albums (party shootings) and I want to list them for my own website (to use Facebook bandwidth)
Here is my source code :
<?php
ob_start();
session_start();
include_once('facebook.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Albums</title>
</head>
<body>
<?php
$params = array(
'appId' => APP_ID,
'secret' => APP_SECRET,
);
$facebook = new Facebook($params);
$user = $facebook->getUser();
$log = null;
if ($user) {
$log = $facebook->getLogoutUrl();
} else {
$log = $facebook->getLoginUrl(array('scope' => 'user_photos'));
}
echo '' . (($user) ? 'logout' : 'login') . '';
if ($user) {
$data = $facebook->api(
'/me/albums',
'GET',
array(
'fields' => 'id,name,privacy,photos.fields(id,name,images)',
'limit' => '300'
)
);
foreach ($data['data'] as $album) {
echo '<div>';
echo '<h3>' . $album['name'] . ' ' . $album['privacy'] . '</h3>';
echo '<textarea style="width: 800px; height: 500px;">';
foreach ($album['photos']['data'] as $photo) {
echo $photo['images'][0]['source'].'';
}
echo '</textarea>';
echo '<textarea style="width: 800px; height: 500px;">';
foreach ($album['photos']['data'] as $photo) {
echo $photo['images'][7]['source'].'';
}
echo '</textarea>';
echo '</div>';
//break;
}
}
?>
</body>
</html>
<?php ob_flush(); ?>
So if you're testing this code, you'll see that it listing to you all your albums but not all the pictures, it stops to 25.
Looks like you use limit in the wrong place. Try-
$data = $facebook->api(
'/me/albums',
'GET',
array(
'fields' => 'id,name,privacy,photos.fields(id,name,images).limit(300)',
'limit' => '50'
)
);
In this case, FB will limit your albums to 50 and the photos within your albums to 300.
Im creating a website where there are table (10x10) with adverts inside (pictures+links). I created this table and created one advert, which leads to testlink.com and has picture "img100x100.png". How could i change the code, so I can get different links and images for each table data cell? Please explain as much as possible, because I have just started to learn PHP & MySQL.
I currently have the following code in index.php:
<?php include 'header.php'; ?>
<body>
<?php
$rows_max = 10;
$columns_max = 10;
$links = Array(
'link' => "http://testlink.com",
'image' => "img100x100.png");
print '<table border="1px" style="border-collapse:collapse;">';
for($row = 1; $row <= $rows_max; $row++)
{
print '<tr>';
for($col = 1; $col <= $columns_max; $col++)
{
print '<td width="10px" height="10px" background="'.$links["image"].'" >';
print '<center> </center>';
print '</td>';
}
print '</tr>';
}
print '</table>';
include 'footer.php'; ?>
and
td a
{
width: 100%;
height: 100%;
display: block;
margin-top: 0px auto;
}
Well you could link this up to a database with 10 rows and foreach through those. Or even simpler, you could have this all in an array. It would be a lot easier if you didn't use a table and just made them square with CSS and floated them left in a container. You would get a similar result.
$links = array(
array(
'url' => 'http://link.com/',
'image' => 'image.jpg'
), array(
'url' => 'http://link.com/',
'image' => 'image.jpg'
), array(
'url' => 'http://link.com/',
'image' => 'image.jpg'
)
// etc
);
Then
foreach($links as $link){
// Code to build out a cell
echo $link['url'];
echo $link['image'];
}
I would like to put a small image icon next to my each category and sub category name (Not replace the category name with an image just put an image after the category name). I have already tried overriding app/core/code/Mage/Catalog/Block/Navigation.php
I changed _renderCategoryMenuItemHtml after which referncing category_id in styles.css I was about to add background image where the code was
$htmlLi .= '>';
$html[] = $htmlLi;
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
with
$htmlLi .= '>';
$html[] = $htmlLi;
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span class="category_'.$this->getCurrentCategory()->getId().'">'.$this->escapeHtml($category->getName()).'</span>';
$html[] = '</a>';
But dint work. I am sure many might have wanted to display a small thumbnail image just after the category name. But just don't know any easy or straight forward way to do it.
Any help is appreciated. Thanks.
Why not use CSS background-image?
Load up the template/catalog/navigation/top.phtml and add in a new class or id for each level's < li > items, maybe something like:
class="nav-<?php echo $_category->getName() ?>"
Then add those classes to your CSS, ie:
.nav-shoes { background: url(images/nav-shoes.png) no-repeat; }
Or even better, build a sprite image with all the images you want to use:
[class^="nav-"] { background: url(images/sprite.png) no-repeat; }
.nav-shoes { background-position: 10px 10px; }
Then all you need to figure out for each image is the background position.
Use this solution for Magento -1.8.*
Go intp Model file. (/app/code/core/Mage/Catalog/Model/Observer.php)
In Function Name: _addCategoriesToMenu
Update following code
$categoryData = array(
'name' => $category->getName(),
'id' => $nodeId,
'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'thumbnail' => Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()
);
Then go into Html folder. (app/code/core/Mage/Page/Block/Html/Topmenu.php)
at line 128 in Function name: _getHtml
Update the following line of code
if($childLevel < 1 ){
$urls = Mage::getBaseUrl('media').'catalog/category/'.$child->getData('thumbnail');
$img = '<img src="'.$urls.'" />';
}
$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . ' </span> '.$img.' </a>';
i am currently having some problems. i am creating a website with a chat feature on it. as of now, we were able to update the area wherein messages would appear upon user submits a message. but we are having some problems. we used jquery so that the whole page would not reload but instead only the iframe alotted for the chat only.the chat would work properly and after a few more minutes, it would start to reload over and over again. here is what we have right now...
<?php
session_start();
include "connect.php";
$room = $_SESSION['room'];
$getnummessages="SELECT COUNT(*) as messagecount from tbl_chatmessages";
$getnummessages2=mysql_query($getnummessages) or die("blah");
$getnummessages3=mysql_result($getnummessages2, 0);
if($getnummessages3>21)
{
$startrow=$getmessages3-20;
}
else
{
$startrow=1;
}
date_default_timezone_set ("Asia/Manila");
$date = date("Y-m-d");
// Configuration part
$path = "images"; // Path to the directory where the emoticons are
//smiley
// Query the database, and assign the result-set to $result
$query = "SELECT emote, image FROM emoticons";
$result = mysql_query($query);
// Loop through the results, and place the results in two arrays
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$emotes[] = $row['emote'];
$images[] = "<img src='" . $path . "/" . $row['image'] . "'>";
}
// The line below replaces the emotes with the images
echo str_replace($emotes, $images, $text);
$getmsg="SELECT * from tbl_chatmessages a, jcow_accounts b WHERE a.room_number='$room' && b.username=a.user_alias && a.date='$date' ORDER BY postime DESC";
$getmsg2=mysql_query($getmsg) or die(mysql_error());
while($getmsg3=mysql_fetch_array($getmsg2))
{
//$message=Smilify($subject); //Smiley faces
print "<table name='tablechat' id='tablechat' cellspacing='0' cellpadding='0' style='margin-top:0px;margin-left:0px;padding:0px;'>";
print "<tr><td rowspan='2'><a href='index.php?p=u/$getmsg3[user_alias]' target='_blank'>
<img src='http://www.pinoyarea.com/uploads/avatars/$getmsg3[avatar]' width='50px' height='50px'/></td><td><font color='#333333' style='text-decoration:none;font-size:14px;font-family:tahoma;'><b> $getmsg3[name]</b></font></a> <font color='#666666' style='text-decoration:none;font-size:10px;font-family:tahoma;'>($getmsg3[time]):</font></td></tr><tr><td><font style='font-family:tahoma;font-size:12px;padding-left:5px;'>".str_replace($emotes, $images, $getmsg3[message])."</font></td></tr>";
print "</table>";
}
function Smilify(&$subject)
{
$smilies = array(
':D' => 'icon_biggrin',
':)' => 'icon_smile',
':(' => 'icon_sad',
':o' => 'icon_surprised',
':shock:' => 'icon_eek',
':?' => 'icon_confused',
':8' => 'icon_cool',
':lol:' => 'icon_lol',
':x:' => 'icon_mad',
':p' => 'icon_razz',
':red:' => 'icon_redface',
':cry:' => 'icon_cry',
':evil:' => 'icon_evil',
':twisted:' => 'icon_twisted',
':roll:' => 'icon_rolleyes',
':wink:' => 'icon_wink',
':!:' => 'icon_exclaim',
':?:' => 'icon_question',
':idea:' => 'icon_idea',
':arrow:' => 'icon_arrow',
);
$sizes = array(
'icon_cry' => 18,
'icon_cool' => 20,
'haha' => 20,
'icon_surprised' => 20,
'icon_exclaim' => 20,
'icon_razz' => 20,
'icon_mad' => 18,
'icon_rolleyes' => 20,
'icon_wink' => 20,
);
$replace = array();
foreach ($smilies as $smiley => $imgName)
{
$size = $sizes[$imgName];
array_push($replace, '<img src="images/'.$imgName.'.gif" alt="'.$smiley.'" width="'.$size.'" height="'.$size.'" />');
}
$subject = str_replace(array_keys($smilies), $replace, $subject);
}
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"> </script>
<script>
$(document).ready(function() {
$("#tablechat").load("chatlog.php");
var refreshId = setInterval(function() {
$("#tablechat").load('chatlog.php?randval='+ Math.random());}, 6000);
});
</script>
Is that the code for the page that gets loaded into the iframe? If so, the problem is probably that you have the code for the timer inside it. Every time you reload the frame you're adding a new interval timer, each time that timer runs it loads a new timer and so on.
The solution is to move the JavaScript you have there at the end out of the iframe and put it in the parent page instead.
the best way i recommend CometD for always pull,it is adavenced technology for push
http://cometd.org/