Bad Code given by Developer for Magento Theme - php

I was given this code by the developer of the magento theme I am using but get an error after placing in the file where I was told to. Can someone please tell me what could be wrong with this code?
<div class="short-description clear">
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription();, 'short_description') ?></div>
</div>

There's an extra ; after $_product->getShortDescription() that doesn't belong there. Also there should be another closing bracket after 'short_description'). Change the PHP line to:
<?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription(), 'short_description')); ?>

Related

Undefined function the_field in Visual Studio Code

I'm trying to display the data of a ACF but I'm getting this error in Visual Studio Code:
This is the entire code. I tried reinstalling the plugin, added PHP to the path but nothing seems to be working.
Single.php
<?php get_header();?>
<div class="container">
<div class="row">
<div>
<img src="<?php the_post_thumbnail_url('thumbnail'); ?>" id="single_header">
<div id="single_content">
<?php if (have_posts()):while (have_posts()):the_post(); ?>
<?php
$fn=get_the_author_meta('first_name');
$lname=get_the_author_meta('last_name');
$email=get_the_author_meta('email');
?>
<h1 class="text=cenetr nt-3 mb-5 text-primary"><?php the_title();?></h1>
<small>Publishor:<?php echo $fn; ?></small>
<p><?php the_content();?></p>
<?php
endwhile;
endif;
?>
<?php previous_post_link(); ?>
<?php next_post_link(); ?>
</div>
<div id="single_extraInfo">
<p>Company: <?php the_field('flight_company'); ?></p>
<p>Date: <?php the_field('flight_date'); ?></p>
<p>Capacity: <?php the_field('flight_capacity'); ?></p>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
On top of what #DaleNguyen adviced above...
Make sure the directory that contains acf plugin is in your Vs Code. Example, instead of only opening the theme directory in Vs Code in which you are probably working, open the entire wp_content directory in your VS Code. That way, when intelephence run in the back-ground, it will be able to reach the plugins folder and acf functions in the acf plugin folder.
In the intelephense, make sure you add wordpress to the list.
#james-serengia answered with one working solution that the ACF plugin folder should be open in the same workspace as the code you are working on and the warning disappears.
Alternatively if that is inconvenient, you can add you can add the ACF stubs to VSCode. It is a bit of messing around but when it is done, it is done. See this explanation.

Wpml and Custom Widgets

In WPML some times custom widgets developed could not get translated.
Any string is translatable if the you copy paste the string then that string if searchable in WPML is translatable.
I have a website that has 4-5 Custom widgets + some hard coded part
For example there was a string in hard coded part-
Bet on your favorite sports online
I made it WPML compatible-
WPML version
N.B. Before posting the question here I have invested around 3-4 hours in understanding all the FAQ's at wpml.org site.
My problem-
I have various widgets, one such widgets has this portion-
<div class="signupoffers">
<div class="signupText"> <h2><?php echo $signup_text_title?></h2>
<p><?php echo $signup_text_content?></p><br>
</div>
<div class="signupbuttonDiv">
<div class="RegisterBlock">
<div class="block"><h2><?php echo $signup_btn_title?></h2>
<div>
<?php echo $signup_btn_content; ?>
</div>
</div>
</div>
<?php //nsu_signup_form();?>
</div>
</div>
Lets take an example this one-
I tried this http://screencast.com/t/3hJCPJgylXS
but the above one doesn't worked.
and various other versions, but no help so far.
Content here is coming dynamically from widget entry. May be I have some syntax issue. Does any one has encountered such situation before, Please guide me how to do that. Thanks!!
Let me ask the question in different way-
The string here is coming in a dynamic format-
<h2><?php echo $signup_btn_title?></h2>
How to convert it into wpml version so that wpml can read and search this string.
I tried this one, but it didn't worked-
<h2><?php _e('(<?php echo $seocontent_text_title;?>)','Casino'); ?></h2>
<h2><?php _e('(<?php echo $seocontent_text_title;?>)','Casino'); ?></h2>
this is definitely wrong
If any of similar approach, it should read similarly to this:
<?php _e( $seocontent_text_title, 'your_text_domain' ); ?>
You would probably also need to edit/create a wpml-config.xml file.
You could also try something along this lines:
(icl_translate function in strings)
<?php echo icl_translate(context, name, value); ?>">
I think this could help you to understand further:
https://wpml.org/forums/topic/transform-echo-to-php_e/
https://wpml.org/documentation/support/translation-for-texts-by-other-plugins-and-themes/
https://wpml.org/documentation/support/wpml-coding-api/

Conditional PHP to show different HTML blocks

I'm working on a login system for a website in which the top right corner will change depending on whether or not the user is "signed in" (a check against a session variable). I am using the following to try and show only one these two states.
<?php if(isset($_SESSION['id'])): ?>
<div class="large-2 large-offset-5 columns">
<p class="right text-pad-top">#MuffinTheFox</p>
</div>
<div class="large-1 columns">
<img class="avatar" src="https://pbs.twimg.com/profile_images/429861192207982592/lxaKQ4Rp.jpeg">
</div>
<?php else: ?>
<div class="large-2 large-offset-7 columns">
<a class="right text-pad-top" href="login.php">Log in/Sign up</a>
</div>
<div class="large-1 columns">
<img class="avatar" src="http://placehold.it/50x50">
</div>
<?php endif; ?>
The problem is, when I upload the code to my server and run it, both HTML blocks display, regardless of the PHP statements.
There aren't any obvious errors and according to my research into the topic, this should work. Also, I tried the way without the endif; statement as well by using brackets, and that didn't work either. At this point I'm somewhat lost as to why this is happening and any help or insight would be appreciated.
Edit: Something of note, the PHP is embedded into a HTML document with a .html extension. I was under the impression that you could just inline php into a html document without issue, but I have a feeling that this might be the cause of the issue.
Your file is not getting parsed as PHP because PHP is not configured to parse .html files unless you tell it to. See this question for insight into how to do that. In the meantime, change your file extension to .php and it should start working as you expect.

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.

All the sudden my links not working in php

I have a page where all links where working properly but all the sudden some links are not working anymore.
I am puzzling myself to undersand why. Nothing really changed. Maybe some css details.
Is there anyone who can give a clue?
Thank you for any help. me abou twhat might have happened.
Francesco
PS sorry forgot to say that looking at the source code the links are there and they work. In design view they just do nothing. They look like normal text.
<div id="centrale"><h1> Upcoming events</h1>
<div class="centrale_event">CLICK HERE TO SEE ALL UPCOMING EVENTS</div>
<p class="line"> </p>
<?php do { ?>
<div class="centrale_event">
<p><img src="<?php echo 'drawings/'.$row_rstevents['event_picture']; ?>" class="float" alt="" /><span class="big"><?php echo $row_rstevents['event_title']; ?></span></p>
<p><strong><em>Starting on <?php echo $row_rstevents['date']; ?></em></strong></p>
<p><strong>Where</strong>: <?php echo $row_rstevents['event_town']; ?></p>
<p><strong>Place</strong>: <?php echo $row_rstevents['place']; ?></p>
<p><?php echo extractFirst($row_rstevents['event_details']); ?> MORE INFO HERE</p>
<p class="line"> </p>
</div>
<?php } while ($row_rstevents = mysql_fetch_assoc($rstevents)); ?>
<div class="centrale_event"><p>CLICK HERE TO SEE ALL UPCOMING EVENTS</p></div>
</div>
Are you using Dreamweaver? I thought you might seeing as you mentioned Design View.. If that's the case then just hit F12 to view in a browser, the design view of DW is pretty lame.
Nothing to do with the link problem, but is there a reason you're using a do {} while () loop to output your database results? Using this construct will output at least one blank event before any actual data shows up, as the first time around the loop, you haven't retrieved any data from the query yet. Any reason you can't do a regular while() { } loop?

Categories