Forum Replies Created

Viewing 15 replies - 91 through 105 (of 130 total)
  • That is correct, spaces or not, it works with the code changes.

    Now if I can get it working in excerpts, I will be happy!

    The code is not very well tabbed to be easy to read, here is a reformatted version, with /*MOD*/ indicators tabbed further out too:

    if($options['customkey_preventduplicatelink'] == TRUE) {  //Prevent duplicate links for grouped custom keywords
    
    	$line = trim($line);
    	$lastDelimiterPos=strrpos($line, ',');
    	$url = trim(substr($line, $lastDelimiterPos + 1 )); 			/*MOD*/
    	$keywords = substr($line, 0, $lastDelimiterPos);
    	$keywords = str_replace(', ', ',', $keywords); 				/*MOD*/
    
    	if(!empty($keywords) && !empty($url)){
    		$kw_array[$keywords] = $url;
    	}
    
    	$keywords='';
    	$url='';
    
    } else {  //Old custom keywords behaviour
    
    	$chunks = array_map('trim', explode(",", $line));
    	$total_chuncks = count($chunks);
    	if($total_chuncks > 2) {
    		$i = 0;
    		$url = trim($chunks[$total_chuncks-1]); 			/*MOD*/
    		while($i < $total_chuncks-1) {
    			if (!empty($chunks[$i])) $kw_array[$chunks[$i]] = $url;
    			$i++;
    		}
    	} else {
    		list($keyword, $url) = array_map('trim', explode(",", $line, 2));
    		$keywords = str_replace(', ', ',', $keywords); 			/*MOD*/
    		if (!empty($keyword)) $kw_array[$keyword] = $url;
    	}
    
    }

    In seo-links.php, starting at line 145 there is an if-else block inside a foreach loop that builds the array that holds the keywords and their respective urls. Add a couple of trim and str_replace functions to get things working properly, four of them as shown below, marked by the /*MOD*/ comments at the end of the lines:

    if($options['customkey_preventduplicatelink'] == TRUE) {  //Prevent duplicate links for grouped custom keywords
    
    				$line = trim($line);
    				$lastDelimiterPos=strrpos($line, ',');
    				$url = trim(substr($line, $lastDelimiterPos + 1 )); /*MOD*/
    				$keywords = substr($line, 0, $lastDelimiterPos);
    				$keywords = str_replace(', ', ',', $keywords); /*MOD*/
    
    				if(!empty($keywords) && !empty($url)){
    					$kw_array[$keywords] = $url;
    				}
    
    				$keywords='';
    				$url='';
    
    			} else {  //Old custom keywords behaviour
    
    			$chunks = array_map('trim', explode(",", $line));
    			$total_chuncks = count($chunks);
    			if($total_chuncks > 2) {
    				$i = 0;
    				$url = trim($chunks[$total_chuncks-1]); /*MOD*/
    				while($i < $total_chuncks-1) {
    					if (!empty($chunks[$i])) $kw_array[$chunks[$i]] = $url;
    						$i++;
    					}
    				} else {
    					list($keyword, $url) = array_map('trim', explode(",", $line, 2));
    					$keywords = str_replace(', ', ',', $keywords); /*MOD*/
    					if (!empty($keyword)) $kw_array[$keyword] = $url;
    				}
    
    			}

    I’m not positive the last two are needed since it does some trimming already, but my implementation is not using that part of the code (I chose to prevent duplicates), so I have not tested it.

    I take that back, I found where it is supposed to not link the text if it would link to itself. But I found the problem, working on fixing it now.

    It has to do with whitespace around the links and keywords. Quick solution is to remove all spaces around custom keywords and their urls.

    I.E.
    change
    Badan si Badun, http://belajar.indonesiamengajar.org/2012/09/badan-si-badun-alat-peraga-anatomi-tubuh-manusia/
    to
    Badan si Badun,http://belajar.indonesiamengajar.org/2012/09/badan-si-badun-alat-peraga-anatomi-tubuh-manusia/

    This also affects using multiple keywords per line, the link will include the space

    E.G.
    if you add Home Remedies as a keyword:
    Badan si Badun, Home Remedies, http://belajar.indonesiamengajar.org/2012/09/badan-si-badun-alat-peraga-anatomi-tubuh-manusia/
    and it is in the text, it would come out as:
    <a href="http://belajar.indonesiamengajar.org/2012/09/badan-si-badun-alat-peraga-anatomi-tubuh-manusia/"> Home Remedies</a>

    Working on adding some trim functions everywhere so we don’t have this problem.

    Sorry, wrong post, refer to
    this topic

    I ham having the same issue. Looking through the code, I found out that the setting only works to stop it from linking the page title to the same page.

    I.E. – if the page title is “Home Remedies” then it will not link the words “Home Remedies” on that page back to itself.

    No solution yet, just wanted to explain what was happening. I’m looking for a way to mod the plugin so it also doesn’t link custom keywords to their respective pages.

    Thread Starter Chris

    (@web2guru)

    It’s not a fix, but since the buttons are useless in this case, I have hidden them and expanded the scrolling area to the full width. Here are the additional skin styles I added to the bottom of the tango skin.css.

    .jcarousel-prev, .jcarousel-next {
        display: none !important; /* hide buttons */
    }
    .jcarousel-skin-tango .jcarousel-container-horizontal {
        padding: 20px !important; /* remove space for buttons */
        width: 900px !important; /* set to page width */
    }
    .jcarousel-skin-tango .jcarousel-clip-horizontal {
        width: 100% !important; /* use full space for carousel */
    }

    The .jcarousel-container-horizontal width setting was 90% plus the padding, which I reduced since that is where the buttons were, so you could do something like 95%, but using percents doesn’t give you exact measurements and I wanted it to be exactly as wide as my theme, which is 900px, so that is what I used.

    Also not sure why .jcarousel-clip-horizontal was set to 97%, just short of the full width, I guess to put a little more white space between the images and the right arrow, but it is not necessary, and without buttons it looks better at full 100% width.

    Basically, if a post is in more than one category but you only want to display posts from one of those categories, you have to specify the id of the desired category.

    [catlist id=9]

    The rest just gives you more advanced options.

    Sorry, don’t do that, let me correct myself.

    You would only need to use the id of the category you want, not the id of the category you don’t want. Specifying the id of the category you do not want would cause it to not display posts that are in BOTH categories).

    This is all you need:

    // post's first category id is 9
    [catlist id=9]

    On another note…

    I have not fully tested the following code, but it should work. If you are comfortable with editing the theme code, you can do something similar in the loop in single.php (or other desired template). This way you would not need to know the category id, but it would display a catlist on all posts (unless you add some conditionals).

    This code would get the categories that a post is in and only display the catlist for the first category

    $theCategories = get_the_category();
    $category1 = $theCategories[0]->term_id;
    echo do_shortcode("[catlist id=$category1]");

    Like my first code examples, this code will do the same, and excludes posts that are also in the other categories.

    $theCategories = get_the_category();
    $category1 = $theCategories[0]->term_id;
    if(isset($theCategories[1])) $category2 = $theCategories[1]->term_id;
    if(isset($theCategories[2])) $category3 = $theCategories[2]->term_id;
    ...
    echo do_shortcode("[catlist id=$category1,-$category2,-$category3...]");

    Make sure those last two codes blocks are used inside the loop.

    That is correct, it is not possible to do it that way. You would have to use the id of the category you want (or the name with a mod) instead of categorypage.

    i.e. you want posts in category id 9 but not posts also in category 10:

    [catlist id=9,-10]

    Alternatively, there is a modification you can make to use the name setting instead. I’ve posted the updated changes here.

    i.e you want posts in category-a but not posts also in category-b:

    [catlist name=category-a,-category-b]

    It has come to my attention that the first part of this mod could be confusing. In order to have posts that are in all the specified categories except posts that are in other specified categories (your using + and not ,) you need to use +- before the category to exclude.

    Here are some examples:

    // Given example (AND)
    // Only gets posts that are in both categories (+ = AND)
    [catlist name=category1+category2]
    
    // Given example (OR)
    // Gets posts that are in either categories
    [catlist name=category1,category2]
    
    // Mod example (AND, EXCEPT)
    // Get posts in either category-a OR category-b
    // but not posts that are is also in category-c
    [catlist name=category1,category2,-category3]
    
    // Mod example (OR, EXCEPT)
    // Get posts in both category-a AND category-b
    // but not posts that are is also in category-c
    [catlist name=category1+category2+-category3]

    I have not tested the AND shortcode, but it should work. Correct me if I am wrong.

    +1 for wanting this feature.

    The code has changed since this was posted, it is now in two places, near lines 143 and 154. Here is the full if/else block in that area, with the modifications (MOD) shown:

    if (preg_match('/\+/', $this->params['name'])):
            $categories = array();
            $cat_array = explode("+", $this->params['name']);
            foreach ($cat_array as $category) :
              // $id = $this->get_category_id_by_name($category); // MOD - replaced with the following mod
              // MOD
              $id='';
              if(strpos($category, '-')===0){
                $id='-';
              }
              $id .= $this->get_category_id_by_name($category);
              // MOD END
              $categories[] = $id;
            endforeach;
            $this->lcp_category_id = $categories;
    
          elseif (preg_match('/,/', $this->params['name'])):
            $categories = '';
            $cat_array = explode(",", $this->params['name']);
    
            foreach ($cat_array as $category) :
              // $id = $this->get_category_id_by_name($category); // MOD - replaced with the following mod
              // MOD
              $id='';
              if(strpos($category, '-')===0){
                $id='-';
              }
              $id .= $this->get_category_id_by_name($category);
              // MOD END
              $categories .= $id . ",";
            endforeach;
    
            $this->lcp_category_id = $categories;
    
          else:
            $this->lcp_category_id = $this->get_category_id_by_name($this->params['name']);
          endif;

    The syntax is correct, however the categorypage and id settings (and name setting) can not be used together.

    The code goes: if categorypage … elseif name … elseif id

    You would need to use the name or id if the post is in more than one category and you only want the first category.

    I’d like this too, but until then, here is an interesting idea…

    We can use multi-page pages with a separate shortcode for each page, and use the offset setting. Something like:

    [catlist name=mycategory]
    <!--nextpage-->
    [catlist name=mycategory offset=10]
    <!--nextpage-->
    [catlist name=mycategory offset=20]
    ...

    You would have to keep up with how many posts you have and update the page with another page break and shortcode periodically, but it works!

    Thread Starter Chris

    (@web2guru)

    So I have narrowed it down to some conflict with the themes [raw] tags, which are used to stop wpautop from messing with their shortcode output, and when the plugin applies filters to the post content.

    Here is the code they have used for their [raw] tags:

    function my_formatter($content) {
    	$new_content = '';
    	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
    	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
    	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
    
    	foreach ($pieces as $piece) {
    		if (preg_match($pattern_contents, $piece, $matches)) {
    			$new_content .= $matches[1];
    		} else {
    			$new_content .= wptexturize(wpautop($piece));
    		}
    	}
    
    	return $new_content;
    }
    
    remove_filter('the_content', 'wpautop');
    remove_filter('the_content', 'wptexturize');
    add_filter('the_content', 'my_formatter', 99);

Viewing 15 replies - 91 through 105 (of 130 total)