Displaying an attribute in a tab - php

I have been trying to display a product attribute that i created called “PDF” in a tab. I tried to re-use the code that had been used to get the product description but change it to reference my new Attribute, well so i thought.
This is the code i used:
The attribute code is: pdf
Admin title is: PDF
<?php $_pdf = $this->getProduct()->getPDF(); ?>
<?php if ($_pdf): ?>
<h2><?php echo $this->__('PDF') ?></h2>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_pdf, 'pdf') ?>
</div>
<?php endif; ?>
I maybe no where near where i have to be but i am new to magento and new to PHP as well.
I dont want to have to use any extensions if possible.
If you can fix this for me you will be a god! thanks in advance for any help.

You are using $this->getProduct()->getPDF() when you should be using $this->getProduct()->getPdf(). Magento camel cases attribute names for its magic methods.
You could also use $this->getProduct()->getData('pdf').

Related

Display a column integrated in an echo and html

I am stuck with an issue here. I am trying to read out a column (pdf) from my mysql db by php and show it on the website as a link. the column's value are pdf names of files saved on the ftp and i want to display it as a link on the page.
<?
$rs_news=mysql_query("SELECT * FROM news WHERE ueberschrift_$lang NOT LIKE '' ORDER BY id DESC");
if(mysql_num_rows($rs_news)>=1){
?>
<? for($i=0;$i<mysql_num_rows($rs_news);$i++){ ?>
<h4 <? if($i>=1){echo("style='margin-top:24px;'");} ?>>
<?= mysql_result($rs_news,$i,"ueberschrift_$lang"); ?></h4>
<img src="../news/bilder/<?= mysql_result($rs_news,$i,"userfile_1"); ?>" onerror="this.style.display='none';" style="padding-top:3px; padding-right:7px;" width="150px" height="110px" align="left"></img>
<?= mysql_result($rs_news,$i,"langtext_$lang"); ?><br><br><br>
Test
<? } ?>
<? } ?>
I know my coding might be ugly, I am very new to PHP and trying to do simple things but I guess I think too complicated.
I have a DB with rows where SOME have a PDF value and some dont.
What I want is that at displaying it only picks those which have a PDF value and displays it via echo like this:
Test
The default value in the column pdf is NULL, I tried to do it via if empty but didnt succeed.
Please let me know if you have any solution for this.
Thanks.
K.

Can a Joomla module “know” what position it's in? (2)

This is my very first question at StackOverflow.
I was trying to post comment in the post Can a Joomla module "know" what position it's in?, but could find no way to do that so I have to post another question here. Any tips regarding how to do this properly is greatly apprieciated.
Anyway, here is my questions:
I tried the code mentioned in the above post but it seemed didn't work. I'm not only quite new to PHP, but also coding, so I'm not sure if it's me or the code. here's what I did to the module's default.php file:
1)to ensure I insert the code at the right place, I insert
<?php echo(print_r($module)); ?>
and it output 1 at the right position;
2)the position-name that I need to determine is "showcase-a", so I insert code
<?php if ($module->position == 'showcase-a'):?>test<?php endif;?>
to the above place, but this time it does't show anything;
3)then I tried this code:
<?php if ($module):?><span>test</span><?php endif; ?>
But still it does't display "test" at the position as I expected.
4)I tried
<?php if (1):?><span>test</span><?php endif; ?>
and the test "test" displays as good. So I didn't code the IF statement wrong.
Now I'm totally lost. Since print_r($module) outputs 1, $module must be positive, why PHP ignore test in 3)? This is just a side question for the sake of PHP learning. What I still need to solve is let the module determine which position itself is in.
Please help. Thank you!
I'm not sure about using it in the template (although it doesn't seem wrong altogether) but my modules oftentimes access the position like this:
$module->position
in the module (so mod_something.php) so try to put it there, if it's available just set a variable and it will be available in the view too.
If $module->position didn't work for you. $module->position may only work for joomla 1.7, 2.5 and + but i'm not sure. $module->position works in joomla 2.5.
Otherwise you need to make a module.php function
Check out the file
/templates/you-template/html/modules.php
For example you make your position the following in your template (for example index.php)
<jdoc:include type="modules" name="header" style="includeposition" />
inside of
/templates/you-template/html/modules.php
You make a function like this :
<?php
function modChrome_includeposition($module, &$params, &$attribs){
//Set a value to $module->position
$module->position='WHATEVER YOUWANT';
?>
<div class="moduletable <?php echo $params->get('moduleclass_sfx').' '.$module->name; ?>">
<?php
if($module->showtitle){
?>
<div class="modtitle">
<div class="fleche">
<span>
<?php
echo $module->title;
?>
</span>
</div>
</div>
<?php
}
?>
<div class="modcontent">
<?php echo $module->content; ?>
<div class="clear">
</div>
</div>
</div>
<?php
}
?>
make different functions names that sets different values if needed.
the function name will match the syle you set:
modChrome_includeposition($module, &$params, &$attribs)
because
style="includeposition"
inside of your jdoc.

How to force a wordpress template to parse code instead of plain-text

I have recently installed a new template(more specifically SquirrelTheme - a free template) in my wordpress blog. It happens that I would like to have two buttons on my front page. Let's say button X and button Y. For creating these buttons I use a plugin called "MaxButtons" which allows you to easily create and manage a button and it's functions. After creating the said button, it gives you a shortcode that you can insert in your posts and pages - lets say [maxbutton id="1"] - to display it.
Unfortunately, after editing the template to my liking(removing divs I didn't intend to display), I can't seem to display these two buttons as the template parses plain-text, unlike the pages/posts apparently.
In case you are wondering how I am inserting the shortcode for the buttons, the template can be easily modified through the dashboard, in which I inserted the following in the field that dictates what is displayed on the specific part of my homepage:
[maxbutton id="1"] [maxbutton id="2"]
Like I said before, instead of showing the buttons as intended, I just see exactly what I type in the box.
I believe this is caused by how the template parses the text, as it uses its own function(? - php _e('...')) to echo the text:
<div class="full_content">
<center>
<?php if (squirrel_get_option('squirrel_slidehead') != '') { ?>
<h1><?php echo stripslashes(squirrel_get_option('squirrel_slidehead')); ?></h1>
<?php } else { ?>
<h1><?php _e('We are scope, a design firm in England', 'squirrel'); ?></h1>
<?php } ?>
<?php if (squirrel_get_option('squirrel_slidedesc') != '') { ?>
<h2><?php echo stripslashes(squirrel_get_option('squirrel_slidedesc')); ?></h2>
<?php } else { ?>
<p><?php _e('Newfoundland dogs are good to save children from drowning, but you must have a pond of water handy and a child.', 'squirrel') ?></p>
<p><?php _e('From drowning, but you must have a pond of water handy and a child.', 'squirrel'); ?></p>
<?php } ?>
</center>
</div>
My question is, how can I get it to display the buttons or any other code.
Thanks in advance.
You can call the function do_shortcode() to do the proper shortcode processing on some text.
Example:
echo do_shortcode('This is a button: [maxbutton id="1"]');

Showing duplicate links with magic fields wordpress

I'm trying to Display a download link using two fields in the backend using magic fields (wordpress)
My code to display one link is.
<?php if (get('upload_file') != "") { ?> <p>Download - <?php echo get('upload_file_name'); ?></p>
<?php } ?>
This works fine and displays it as a link on the front end.
But my magic fields are in groups. So when i duplicate a group the in the back end. and add another name and file etc. It does not show in the front end. it just shows the one.
Can any one show me how to get the links showing in the front? no matter how many times i duplicate the fields?
Hope this made sense.
I've fixed this.
This is the code i used. incase anyone wants to know.
<?php $members = get_group('upload'); ?>
<?php foreach ($members as $member): ?>
<p> Download - <?php echo $member['upload_file_name'] [1] ?></p>
<?php endforeach; ?>

Display certain HTML in an Automatically generated PHP page?

How can I display a certain HTML code in a php generated page.
For example, php will automatically display the name and category of an item, yet I want to add custom pictures to this generated page. Is there any way to do this without creating a separate HTML page to include into the generated page?
I'm hoping for something like a database entry where to add the html part to display. Is it possible?
ps. Sorry if I didn't express my idea in a completely understandable way.
Store the image URLs just like you are storing the names and categories. Then you would just do something like:
<span id="name"><?= $name ?></span>
<span id="category"><?= $category ?></span>
<img src="<?= $image ?>" />
Maybe you need to clarify - why do you need different HTML for each page, if the only thing changing are the images?
Keep in mind here I use <?= $foo ?> which is generally considered bad practice, and is just shorthand for <?php echo $foo; ?>.
Just wrap the PHP in your HTML:
<h1>My Test</h1>
<?= $myCategory; ?> - <?= $myItem; ?>
<img src ="mySource" alt="myImg" width="15" height="15" />
This also works for your HTML in your Database:
<p><?= $myDatabaseHTMLContent ?></p>
Cheers,
Max
<?php
//Your php code
?>
<img src="" />
<?php
//Your php code
?>
You can put html in a php file, like the example above.

Categories