The following query will extract only unique pairs of item and attribute (or its parent if any), thus eliminating the duplicates (this is per your request that an attribute can have only one parent, and the parent has no parents).
SELECT DISTINCT I.item_id AS iid, A.par_id AS aid
FROM
items AS I,
(SELECT AA.attr_id, IF(AA.parent_id = 0, AA.attr_id, AA.parent_id) AS par_id
FROM attribute AS AA) AS A
WHERE I.attr_id = A.attr_id
ORDER BY I.item_id
So, using the above query as a subtable for your counting query will work (same approach I used with the A subtable above):
SELECT SUB.iid, COUNT(DISTINCT(SUB.aid)) AS attributes
FROM
(SELECT DISTINCT I.item_id AS iid, A.par_id AS aid
FROM
items AS I,
(SELECT AA.attr_id, IF(AA.parent_id = 0, AA.attr_id, AA.parent_id) AS par_id
FROM attribute AS AA) AS A
WHERE I.attr_id = A.attr_id
ORDER BY I.item_id) AS SUB
GROUP BY SUB.iid
HAVING attributes > 1
I have added 3 more rows to your example items table, to accommodate the case, where an item can be linked only to an attribute with parent, but not the parent itself (i.e. item 3 -> 23 and 3 -> 20), and 4 -> 23.
Running the above query lists only items 2 and 3 with 2 attributes each.