Jump to content

mnybud

Members
  • Posts

    80
  • Joined

  • Last visited

Everything posted by mnybud

  1. Good advice but I am not very good at PHP (obviously) so did what I could figure out and modified it in a way that works for me. It has been this way for over a year with no problems There is not a good way to filter out products in woocommerce for my use as I am actually filtering out the $0 products and not actual out of stock items. Thanks again for the advice but for now I am just looking for a way to modify the code above.
  2. Hi. I need some help making some changes to some code. I have tried several things and still can't seem to get it right so hoping someone here can help me out. This is the original code I wrote that I am trying to change.... <?php do_action( 'woocommerce_before_shop_loop_item' ); ?> <a href="<?php the_permalink(); ?>"> <?php /** * woocommerce_before_shop_loop_item_title hook * * @hooked woocommerce_show_product_loop_sale_flash - 10 * @hooked woocommerce_template_loop_product_thumbnail - 10 */ do_action( 'woocommerce_before_shop_loop_item_title' ); ?> <?php echo $product->is_in_stock() ? '' : '<img src="notavailable.png" class="attachment-shop_catalog wp-post-image">'; ?> <h3><?php the_title(); ?></h3></a> <?php do_action( 'woocommerce_after_shop_loop_item' ); ?> What I am trying to accomplish is to make it so my shop only shows the product if it is in stock. Currently the code above adds a notavailable.png to out of stock items but still displays them. I tried something like this but I am not able to make it work. <?php echo $product->is_in_stock() ? ' <?php do_action( 'woocommerce_before_shop_loop_item' ); ?> <a href="<?php the_permalink(); ?>"> <?php /** * woocommerce_before_shop_loop_item_title hook * * @hooked woocommerce_show_product_loop_sale_flash - 10 * @hooked woocommerce_template_loop_product_thumbnail - 10 */ do_action( 'woocommerce_before_shop_loop_item_title' ); ?> <h3><?php the_title(); ?></h3></a>' : ''; ?> <?php do_action( 'woocommerce_after_shop_loop_item' ); ?> If anyone can help me get this right I would really appreciate it.
  3. I have limited PHP knowledge and have been fighting with something that is probably not to hard for you PHP freaks so hoping someone can provide me with a solution. Here is what I am trying to accomplish... I have this code that works. <?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $product; ?> <?php echo $product->is_in_stock() ? 'in stock' : 'out of stock'; ?> What I am trying to get working is this below but so far I am having no luck figuring it out with my lack of PHP knowledge. More or less I am trying to echo my form which has some other PHP code that breaks it. Can anyone help? Thanks so much in advance! <?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $product; ?> <?php echo $product->is_in_stock() ? ' <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?> <form name="order" action="<?php echo esc_url( $product_url ); ?>" method="post"> <input type="image" src="image.png" onClick="ga('send', 'event', { eventCategory: 'Button', eventAction: 'click', eventLabel: 'Button'});"/> </form> <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?> ' : 'out of stock'; ?>
  4. anyone else help. the suggested code above actually doesnt even work on a single term
  5. well obviously I suck at PHP, which would be why
  6. thanks but that still is not working. It works if the page title is one word but not if it is more than one. and in this case the urls do include a space....example. max results http://www.amazon.com/rss/tag/ipod accessories/new/ref=tag_tdp_rss_new_man?tag=biblesforthew-20 limited results http://www.amazon.com/rss/tag/ipodaccessories/new/ref=tag_tdp_rss_new_man?tag=biblesforthew-20
  7. Trying to figure this out... <?php echo get_the_title(); ?> works to display my wordpress post title on the page. how can I echo that inside this code? <?php if (function_exists('simple_feed_list')) : ?> <?php simple_feed_list('I WANT TO ECHO TITLE HERE'); ?> <?php endif; ?>
  8. I have also tried this with no luck... anyone have any ideas? <?php if (function_exists('simple_feed_list')) : ?> <?php $title = get_the_title(); simple_feed_list('http://www.amazon.com/rss/tag/'. str_replace("", "", $title) .'/new/ref=tag_tdp_rss_new_man?tag=search-20','limit=5&desc=yes&nofollow=yes&more=no'); ?> <?php endif; ?>
  9. I am trying to learn PHP and am a novice so please excuse the stupid question but I have researched and attempted to find a solution for this and cant. Hoping someone can help me. I have the following code I am using within a Wordpress template... <?php if (function_exists('simple_feed_list')) : ?> <?php $title = get_the_title(); str_replace("+", " ", $title); simple_feed_list('http://www.amazon.com/rss/tag/'. str_replace(" ", "+", $title) .'/new/ref=tag_tdp_rss_new_man?tag=search-20','limit=5&desc=yes&nofollow=yes&more=no'); ?> <?php endif; ?> I am trying to make it produce a RSS feed url from amazon that looks like this: http://www.amazon.com/rss/tag/ipod ibuds/new/ref=tag_tdp_rss_new_man?tag=search-20 note the space between ipod and buds, that is what I am trying to accomplish. Right now the space is being changed I think to a + sign which breaks the feed if the search term is more than one word. Can anyone help me fix this? I have tried removing the string replace part, etc with no luck
  10. is it not possible? Everything I try breaks things
  11. I actually want to replace it in the wp_title portion, how would I modify it to do that since it is using print? <?php elseif ( is_single() ) { wp_title(''); print ' | '; str_replace("'", "", bloginfo('name')); } ?> (thanks a lot for the help)
  12. yes I got that but how would I insert it properly in the code above is my problem....can you give a working example with the code above please? Thanks for the help!
  13. First and foremost I am PHP newbie so excuse the dumb question but I have been struggling with this one for hours and can not find the solution. Can someone show me how I would rewite the following wordpress code for meta tags so that it automatically strips out the character ' from the "single" page titles? Example I want this title: "My Cat's Black" to be "My Cats Black" This is the line I am trying to edit..... elseif ( is_single() ) { wp_title(''); print ' | '; bloginfo('name'); } here is the full piece of code... <title><?php if ( is_home() ) { bloginfo('name'); print ' | '; bloginfo('description'); } elseif ( is_search() ) { bloginfo('name'); print ' | '; _e('Search Results', 'woothemes'); } elseif ( is_author() ) { bloginfo('name'); print ' | '; _e('Author Archives', 'woothemes'); } elseif ( is_single() ) { wp_title(''); print ' | '; bloginfo('name'); } elseif ( is_page() ) { bloginfo('name'); print ' | '; bloginfo('description'); } elseif ( is_category() ) { single_cat_title(); print ' | '; bloginfo('name'); } elseif ( is_month() ) { _e('Archive', 'woothemes'); print ' | '; the_time('F'); bloginfo('name'); } elseif (function_exists('is_tag')) { if ( is_tag() ) { bloginfo('name'); print ' | '; _e('Tag Archive', 'woothemes'); print ' | '; single_tag_title("", true); } } ?></title> Any help would be greatly appreciated!!
  14. I am a total newbie at PHP and I have a wordpress plugin that works well but sometimes does not return any results to the query which I believe is causing this error: Warning: Invalid argument supplied for foreach() social-media-integrated-related-content-smirc/lib/smirclib.php on line 182 From what I am reading on other forums the problem is possibly that the foreach loop is empty since the array must have elements. The solution being to add a check above the foreach loop, to count the number of elements in the array, and if it is zero, skip the foreach loop. Is this correct? Here is the code....can someone please edit it so I can see an example of how it should be done? Again total PHP newbie so please be clear if possible. Thanks so much!!! <? /** * Object for getting, parsing, and prepping external related content * * @author Husani S. Oakley * @version 1.0 */ class SMIRC{ var $total_results; var $page_title; var $default_header_text = "Blog discussions:"; var $search_urls = array( "google_blogsearch_norss" => "http://blogsearch.google.com/blogsearch?client=news&um=1&hl=en&scoring=d&q=SEARCHTERM&ie=utf-8", "google_blogsearch" => "http://blogsearch.google.com/blogsearch_feeds?client=news&um=1&hl=en&scoring=d&q=SEARCHTERM&ie=utf-8&num=NUMRESULTS&output=rss", "twitter_search" => "http://search.twitter.com/search.atom?q=SEARCHTERM&rpp=NUMRESULTS" ); /** * constructor */ function SMIRC($page_title, $title_separators, $required_keyword, $data_sources, $header_text, $animation=false){ $this->page_title = $page_title; $this->title_separators = $title_separators; $this->required_keyword = $required_keyword; $this->data_sources = $data_sources; if($header_text == ""){ $this->header_text = $this->default_header_text; } else { $this->header_text = $header_text; } $this->animation = $animation; } /** * main work method. create url, get data, parse, prep and return xhtml */ function getContent(){ //don't bother doing anything if we don't have any data sources if(!is_array($this->data_sources)){ return false; } //if we have delimiter characters, use them to split up the title $searchterm = $this->_getSearchTerm(); //start assembling data foreach($this->data_sources as $source_array){ //prep url $data_source = str_replace("SEARCHTERM", $searchterm, $this->search_urls[$source_array[0]]); $data_source = str_replace("NUMRESULTS", $source_array[1], $data_source); //get data, put into array $rss_data_array[$source_array[0]]['results'] = $this->_getResults($data_source, split("\n", $source_array[2])); $rss_data_array[$source_array[0]]['header'] = $source_array[3]; } //create and return xhtml for all sources $xhtml = $this->_createXHTML($rss_data_array, $this->header_text); return $xhtml; } /** * create and return all xhtml */ function _createXHTML($rss_array, $header_text){ foreach($rss_array as $data_source => $results_and_header){ //run function to get xhtml from rss object -- name of function depends on data source. $lists_xhtml .= $this->$data_source($results_and_header['results'], $results_and_header['header']); } if($lists_xhtml == ""){ //no results = no xhtml return false; } else { $all_xhtml = '<div class="smirc_wrapper">'; $all_xhtml .= '<h2 class="collapsed">'.$this->_getHeaderXHTML().'</h2>'; $all_xhtml .= '<ul class="smirc_ul">'; //add results to overall xhtml $all_xhtml .= $lists_xhtml; $all_xhtml .= "</ul>"; $all_xhtml .= '</div>'; return $all_xhtml; } } /** * GOOGLE BLOGSEARCH: iterate through rss object and create standards-compliant xhtml for the resultset, while ignoring items in exclude list */ function google_blogsearch($rss_items, $result_header){ $list_xhtml = ""; if(count($rss_items) >= 1){ $list_xhtml = ""; foreach($rss_items as $item){ $fixed_item = $this->_parseItem($item); $list_xhtml .= '<div class="summary">'.strip_tags($fixed_item['summary']).'</div></li>'; } } return $list_xhtml; } /** * TWITTER SEARCH: iterate through rss object and create standards-compliant xhtml for the resultset * search.twitter.com doesn't seem to have results limits, so we'll have to do that manually. */ function twitter_search($rss_items, $result_header){ $list_xhtml = ""; if(count($rss_items) >= 1){ $list_xhtml = ""; foreach($rss_items as $item){ $fixed_item = $this->_parseItem($item); $list_xhtml .= '<li>'.$fixed_item['atom_content'].' by <a href="'.$fixed_item['author_uri'].'" rel="nofollow" target="_blank">'.$fixed_item['author_name'].'</a></li>'; } } return $list_xhtml; } /** * use title separators (if any) to prepare search term(s) */ function _getSearchTerm(){ if(is_array($this->title_separators)){ //make this easy -- replace all matches to items in separators array with a common character $title = $this->page_title; foreach($this->title_separators as $delimiter){ $title = str_replace($delimiter, "###", $title); } //split by this common character $arr = split("###", $title); //iterate, trim, add to array foreach($arr as $phrase){ $searchterms[] = trim($phrase); } $searchterms[] = $this->required_keyword; } else { //no separators. search terms are title and required keyword if any $searchterms[] = $this->page_title; $searchterms[] = $this->required_keyword; } //iterate through searchterms and add quotation marks / urlencode as needed $str = a; foreach($searchterms as $term){ $str .= '' . urlencode($term) . ''; } return $str; } /** * using the exclude list (if set) and MagpieRSS, return an array of data sources and results */ function _getResults($data_source, $exclude_list){ $rss = fetch_rss($data_source); //set total results $this->_setTotalResults($rss); $results = $rss->items; //is there an exclude list? if(is_array($exclude_list)){ //yes. iterate and remove foreach($exclude_list as $exclude_me){ $matches = $this->array_search_recursive($exclude_me, $results); unset($results[$matches[0]]); } } return $results; } /** * unfortunately-ghetto way to remove google's BOLDING of matching wordds */ function _parseItem($arr){ $newarr; if(!is_array($arr)){ return $arr; } foreach($arr as $key => $value){ $newval = str_replace("<b>", "", $value); $newval = str_replace("</b>", "", $newval); $newarr[$key] = $newval; } return $newarr; } /** * recursively search a multidimensional array */ function array_search_recursive($needle, $haystack, $path=array()){ foreach($haystack as $id => $val){ $path2 = $path; $path2[] = $id; if(eregi($needle, $val)){ return $path2; } else if(is_array($val)){ if($ret = $this->array_search_recursive($needle, $val, $path2)){ return $ret; } } return false; } } /** * add to total results count */ function _setTotalResults($rss){ if($rss->channel['opensearch']['totalresults']){ $this->total_results = $this->total_results + $rss->channel['opensearch']['totalresults']; } } /** * create header text / link */ function _getHeaderXHTML(){ //create link $link = str_replace("SEARCHTERM", $this->_getSearchTerm(), $this->search_urls['google_blogsearch_norss']); return " "; } } ?>
  15. I was hoping someone could help with a newbie question. I am trying to insert a echo into a include and it obviously is not possible how I am doing it. Can anyone give me some suggestions on how to make it work? Here is what I am trying to do... I have these 2 pieces of code which both work fine by themselves: <?PHP include('parser.php?query='); ?> <?php echo $rsAnswer[$i]->answer_text;?> and I am trying to make it work like this so the echo file sets the includes query.... <?PHP include('parser.php?query=<?php echo $rsAnswer[$i]->answer_text;?>'); ?> I know this is not right but can someone show me how to fix it? ???
  16. Hi thanks for the reply and I understand the best way would be to echo the $variable; in the included php directly but that page is complex and over my head to edit. Is there a way I can just echo it within the include on the actual page like I asked above?
  17. Newbie questions time I am trying to accomplish the following: I have a url formated like this: http://www.domain.com/?word_I_want=thisword I can echo "thisword" fine on my page with <?PHP echo $_REQUEST['word_I_want']; ?> But I also need to include it within this after ?query= <?PHP include("parser.php?query=word_I_want") ?> I know this should be simple but I have tried several variations of what I thought might work and keep getting syntax errors. Can anyone help me out please?
  18. dirty or not it works now, thanks!
  19. yes but what setting do I change? I cant find it. Thanks in advance!
  20. All my php scripts start with <? but I installed PHP locally and my php.ini requires my scripts to have <?php Is there a way to fix this without editing all my scripts?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.