You can connect a task to a specific opportunity if that task is linked to a specific contact. To connect a task to a specific opportunity, you can either go to edit task and choose opportunity on edit window or from detail view, click on connect opportunity button