• Resolved brettsandersuk

    (@brettsandersuk)


    Hi all,

    I have tried and tried to do this, but I’m a bit of a novice and I need some direction. Thanks in advance to anyone who might be able to help.

    The site is: https://www.thegymbuzz.com

    The current issue is: Half way down the page, where it says “Browse by Well-Known Brands”, the categories that are in there have some space between each line. I can’t seem to remove it.

    I believe the coding for this is in the plugin itself and not the theme (but, of course, I might be wrong.) I have been into the coding and taken out what I didn’t need and experimented removing different bits to see what worked but nothing has.

    The code is:

    <?php
    /*
    Plugin Name: Category Post List
    Plugin URI: https://www.jameswilkesdesign.co.uk/wordpress-plugin-to-display-all-posts-in-all-categories/
    Description: Gives a complete list of categories and all the posts in them.
    Version: 1.3
    Author: James Wilkes
    Author URI: https://www.jameswilkesdesign.co.uk/
    License: GPL3
    
    Copyright (c) 2010 James Wilkes https://www.jameswilkesdesign.co.uk/
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
    */
    
    set_time_limit(20);
    ini_set("memory_limit","128M");
    
    function jameswilkes_catpostlist_content_handler ($content) {
    	$tag = "[jwcatpostlist";
    	$closetag = "]";
    
    	$i = -1 + stripos("x" . $content, $tag);
    	$j = -1 + stripos("x" . $content, $closetag, $i + 15);
    
    	if (($i >= 0) && ($j >= 0)) {
    		$before = substr($content, 0, $i);
    		$after = substr($content, $j + strlen($closetag), strlen($content) - $j - strlen($closetag));
    
    		$tagcontent = substr($content, $i + 1, $j - $i - strlen($closetag));
    
    		$categorylist = array();
    		$postlist = array();
    
    		$orderby = "date";
    		$order = "asc";
    
    		$orderby_accepted_values = array('date', 'modified', 'title');
    		$order_accepted_values = array('asc', 'desc');
    		$params = explode(" ", strtolower($tagcontent));
    
    		$gotincludecats = false;
    		$includecats = array();
    		$excludecats = array();
    		foreach ($params as $param) {
    			$name = "";
    			$value = "";
    			if (strpos($param, "=") > 0) {
    				$name = substr($param, 0, strpos($param, "="));
    				$value = substr($param, strpos($param, "=") + 1);
    			}
    			if ($name == "orderby") {
    				if (in_array($value, $orderby_accepted_values)) {
    					$orderby = $value;
    				}
    			} else if ($name == "order") {
    				if (in_array($value, $order_accepted_values)) {
    					$order = $value;
    				}
    			} else if ($name == "includecats") {
    				$includecats = explode(",", $value);
    				$gotincludecats = true;
    			} else if ($name == "excludecats") {
    				$excludecats = explode(",", $value);
    			}
    		}
    
    		$posts = get_posts("orderby=" . $orderby . "&order=" . $order . "&numberposts=9999");
    		foreach ($posts as $post) {
    			$postname = get_the_title($post->ID);
    			$postlink = get_permalink($post->ID);
    			$categories = get_the_category($post->ID);
    			$postlist[$postlink] = array($postname, $categories);
    			foreach($categories as $cat) {
    				$catID = $cat->cat_ID;
    				$catname = $cat->cat_name;
    				if (!array_key_exists($catname, $categorylist)) {
    					$categorylist[$catname] = $catID;
    				}
    			}
    		}
    
    		// get list of category IDs ordered by name
    		$sortedcats = array();
    		foreach ($categorylist as $catname=>$catID) {
    			array_push($sortedcats, $catname);
    		}
    		sort($sortedcats);
    
    		foreach ($sortedcats as $catname) {
    			$catID = $categorylist[$catname];
    
    			$usecat = true;
    			if ($gotincludecats) {
    				$usecat = in_array("" . $catID, $includecats);
    			}
    			if (in_array("" . $catID, $excludecats)) {
    				$usecat = false;
    			}
    
    			if ($usecat) {
    				$postlisttext .= "<class=\"jwcatpostlist\"><a href=\"" . get_category_link($catID) . "\">$catname</a>\n";
    				$postlisttext .= "<ul class=\"jwcatpostlist\">\n";
    				foreach ($postlist as $postlink=>$postdata) {
    					$found = false;
    					foreach($postdata[1] as $postcat) {
    						if ($postcat->cat_ID == $catID) {
    							$found = true;
    						}
    					}
    					if ($found) {
    					}
    				}
    				$postlisttext .= "</ul>";
    			}
    		}
    		$content = $before . $postlisttext . $after;
    	}
    	return $content;
    }
    add_filter('the_content', 'jameswilkes_catpostlist_content_handler');
    
    ?>

    Thanks and hopefully someone can guide me here.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think if I understand your issue correctly, you’re looking to reduce the whitespace between different category unordered lists? Shouldn’t require messing around with the plugin.

    Just go into the theme’s stylesheet here in the wp-content folder:

    …/wp-content/themes/los_angeles/assets/css/core.css

    look at line 340 of the “core.css” file:

    #page ul#entries li ul, #page {
    list-style-type: none !important;
    margin-bottom: 10px;
    margin-top: 10px;
    }

    You can change the “margin-bottom” property to reduce spaces at the bottom of each category list.

    If you want to tighten the whitespace around the items in each category, adjust the spacing between the list items (line 345):

    #page ul#entries li ul li {
    border: 0px;
    margin-bottom: 5px;
    padding: 0px;
    }

    I played around with it here in firebug, seems to change the whitespace.

    Thread Starter brettsandersuk

    (@brettsandersuk)

    Thanks you have really helped.

    First, I tried what you suggested but it didn’t do what I had hoped.

    So you inspired me to use Firebug, which I had always put off using because I didn’t think I would “get it”, and find the solution myself.

    It was the line-height which was set to 20px instead of “normal” as with all of the other lists.

    I have now changed that and I am sorted. And I now have a new tool in Firebug, so thanks for that!

    Great! Firebug or any of the development tools bundled with Chrome or Safari are really indispensable and save a lot of time. Glad you found it useful.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Space between lines – Can't remove them?!’ is closed to new replies.