To get number of cart items in Magento e.g. to display in the mini-cart or header of your Magento e-commerce website, you can call the getSummaryCount() function in Mage Helper file checkout/cart:

echo $this->helper('checkout/cart')->getSummaryCount();

The above code grabs the total number of items in the cart i.e. it considers the quantity of each item as well e.g. if there are two products / items in the cart and quantity is 2 for both of them, then the above function will return value as 4.

But if you just want to display the items count i.e. without considering the quantity of each item, you can call the below function:

echo $this->helper('checkout/cart')->getCart()->getItemsCount();

And in case if you want to get the total price of the items in the cart, you can use this function:

echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal());