I would like to request information of how to extract a particular value in getpath() function.
currently I placed the following information:
<?php $currentCat = Mage::registry('current_category'); ?>
<?php echo $currentCat->getPath()?>
and the system echo 1/2/5 , where 1 is root of root, 2 is catalog root and 5 is the first simple category.
I would like to extract the third value only (number 5 in this example) in that serie of categories to echo that info only in the page but i tried different appraches with no success.
thank you.
explode(), end()
<?php echo end(explode("/", $currentCat->getPath())); ?>
do you know if I can place a value to retrieve always that 3 level no matter if im placed in another subcategory
Should looks like this:
<?php
$exp = explode("/", $currentCat->getPath());
echo $exp[2];
?>
I would recommend you to take a look at explode() again :)
Related
I have multiple options in an attributes in Magento and when I call the attribute, all of the options show in a string and I would like to show them on separate lines (p tags or li's).
<?php echo $this->getChildHtml('spamodel') ?>
The above is my code, I think i need to use explode but I'm a newbie at php.
Thanks for any help.
<?php $spamodel = $this->getChildHtml('spamodel');
$spamodel_explode = explode(",",$spamodel);
echo $spamodel_explode[0];
?>
Here you can go with this code. you can get single the names with $spamodel_explode[0] and if you want to get all the names than you can use forloop
Here You can able to get the answer
<?php
$variable = $this->getChildHtml('spamodel')
$variable_exp = explode(",",$variable)
foreach($variable_exp as $var){
echo $var;
}
?>
In above coding you can explode based on your requirement.Just replace the ',' tag and get the results based on your requirement.
Find the below link for more details.
http://www.brandammo.co.uk/output-magento-custom-attributes-to-front-end-from-multi-select-dropdowns/
I am writing an application that will look at a single record, obtain values from about 12 flags (0 or 1), look up those flags against a status table (in MySQL) and return a variable called $status_message which is in that table.
In this table I need to have hyperlinks (working fine) but also echo some variables, i.e.
You have no bids for {{$row->_item_name}}
or
View this item now by clicking here
Now I need item name and the other example to be translated into <?php echo $row->_item_name; ?>
I have tried a preg_replace with the following:
<?php
$find = array('/{{/', '/}}/');
$replace = array('<?php echo ', ' ?>');
echo preg_replace($find, $replace, $status_message);
?>
but this is not working.
Can anyone advise how I can get the desired result and 'echo' the variable in the MySQL field?
Had a brainwave. Much simpler,
instead of $row->_item_name I just put {{itemname}} in the string. I then use the following code:
<?php
$message_buyer = str_replace('{{itemname}}', $row->_item_name , $message_buyer);
echo $message_buyer;
?>
so no need to have <?php calls in the string at all.
I'm trying to find the category ID of a post and then use it in the short code below. To find the category id I'm using <?php the_category_ID(); ?>, but i'm not sure how to use the output from category id and replace it in include_categories=. i.e. i want to replace number 4 with the current category ID i got from <?php the_category_ID(); ?>.
<?php echo do_shortcode('[include_categories="4"]'); ?>
i tired doing the following, but it didn't work. Any ideas will be appreciated.
<?php echo do_shortcode('[include_categories="<?php the_category_ID(); ?>"]'); ?>
I know i can't use php inside another php code, but i'm not sure how to place the category id between the quotation.
Thanks.
A couple of things: (1) you can't have nested <?php ?> tags, (2) the_category_ID() has been deprecated since WordPress 0.71. You'll want to use get_the_category() instead.
The correct solution would be:
<?php echo do_shortcode('[include_categories="' . get_the_category() . '"]'); ?>
The dots . "concatenate" the string with the returned values of get_the_category(). You can read more about string operators in the PHP docs.
Try with -
<?php echo do_shortcode('[include_categories="'.the_category_ID().'"]'); ?>
Use this to add php verial in short code:
<?php $category=the_category_ID();
echo do_shortcode("[include_categories=$category]"); ?>
I'm trying to seperate each output individually. Is there any possible way to do this ?
<?php echo stripslashes($row['meta_keys'] = str_replace(',',' ',$row['meta_keys'])) ?>
I want to link each one to a specific thing, but it all comes out as 1 a link
I did <?php echo stripslashes($row['meta_keys'] = str_replace(',',' ',$row['meta_keys'])) ?> but again, it all came out as one link. Any simple way to do this?
I'm currently using a wordpress function in order to display posts from a specific category. A simplified example is shown below:
<?php query('cat_name=cat1&posts=1') ?>
Essentially this gets 1 post from the category cat1.
However I have a variable saved which gets the current category (this is on category pages):
<?php $thiscat = get_the_category(); ?>
Current Category: <?php echo $thiscat ?>
How can I now echo the variable $thiscat into the arguments of my query above so that the category name is filled in for me? This function is applied on different category pages so having it automatically passed to the arguments of my query saves a lot of hassle.
Thanks in advance for any help.
You only echo something when you want to output it to the browser, here we concatenate the query string with the variable:
<?php $thiscat = get_the_category(); ?>
<?php query('cat_name=' . $thiscat . '&posts=1') ?>
Not sure I understand the question, but it sounds like you want to use $thiscat in your query. This should do it:
<?php
$thiscat = get_the_category();
query("cat_name=$thiscat&posts=1")
?>
Note the double quotes, which are necessary. If you use single quotes, the variable will not get expanded.