First we need to analyse what factors made WWI into trench warfare. Those factors are: rifles, machine-guns, artillery, grenades, transportation and the size of the conflict.
Then, we can think about how your magic can emulate those factors. Finally, I'll touch on how those aspects effect staples of the fantasy setting: knights, close combat, and medieval army structures.
CREATION OF TRENCH WARFARE
How it happened historically; and how your magicians can do it
The rifles of WWI are a factor in creating trench warfare, because they had much greater range, accuracy, and rate of fire compared to firearms of conflicts beforehand.
Rifles were intended to be shot up to 1.5 to 2km away to saturate an area with bullets and deny it to the enemy. A lot of rifle historians (e.g. Paul Scarlata) consider this not very effective as a tactic, but either way most rifles from 1870 to WWI were built with sights intended for this very long range. Whether it worked well or not, it was expected, and people were trying it.
So, your mages should have long-range rapid-fire saturation effects - such as your mentioned lightning bolts.
Rifles varied of course in accuracy but are capable of immensely precise shots, more so than a crossbow. There is a lot of crossover here with range as a factor. Armies up to the 16th century could and would line up within a kilometer or within a mile without getting shot to bits. A crossbow is accurate enough to aim at a single person and hit half the time maybe at 50-100 yards. You can aim at a group of men at 200-300 yards. That's it, and the longbow and all firearms up to about 1550 have comparable range and accuracy. Muskets up to about 1840 would only max at about 400 yards. A rifle of the first world war has a much better accuracy. Off-hand I can think of this example of long range shooting (http://www.youtube.com/watch?v=fhaY3pa1oio). That's hitting a 3-foot by 10 inch target half the time at 1,000 yards. It's also an older 1886 rifle without smokeless powder or spitzer bullets, so is inferior to many of the 'new' rifles of WWI. But will serve as an example.
A modern charger or box magazine rifle of WWI could shoot about 20 times per minute. Those magazines were introduced 1886-95 in most nations. but many still had older rifles in service with reserve troops etc. France had 150,000 Gras rifles (1874), and 10% of Russia's rifles were Berdan IIs (1870), but these could still do 10 shots a minute or more. So if your mages are going to replicate a rifle, they need long range and a high rate of fire.
So, your mages - if you want to emulate a rifle - need to be able to threaten groups and areas 1500 to 2000 yards away, need to be able to hit a man 1000 yards away, and shoot 10-20 times a minute. That's not to say that to create trench warfare you actually need to emulate a rifle, or use these exact figures, but they are an option.
I will say now it was not machine-guns that created trench warfare. In 1914 and 1915 machine-guns were generally available at about 2-4 per regiment (1000+) of infantry. Of course their presence was powerful, but in a small area. A strategic location. Put low-grade mages throughout your army to represent rifles, and have individual or small groups of exceptionally powerful casters in strategic locations, like how machineguns were used at first.
As the war progressed, more and more machineguns until they were about 10 times more common (2-4 per company of 100-200 troops), and special assault units had even more, had light machine guns etc. Having your mages emulate late-war machineguns means employing them as strike teams - actually similar to how tanks were then used.
Artillery was a far bigger killer and wounding weapon than machineguns and even more than rifles, even though every soldier carried one. I would say rifles created the trench warfare situation and artillery just made trench warfare a lot more bloody, but it could be argued better artillery forced more trenches and earthworks.
Quick bit of background. Most artillery until about 1860 was smoothbore and muzzleloader. Many nations got guns which were either rifled (much longer range) or breech-loading (much higher fire rate) around 1860, and get the two combined about 1870.
Then the 1897 French Gun comes in (https://en.wikipedia.org/wiki/Canon_de_75_mod%C3%A8le_1897). Being recoilless, it massively improves the accuracy and rate of fire possible for the crew. Every nation quickly gets some of this gun (e.g. UK and USA) or makes something similar (e.g. Germany's 7.7 cm FK 96 n.A) and that's the standard artillery of WWI - WWI was also the first really major usage of such a brutally efficient machine.
I have already stated my historical opinion ("rifles created the trench warfare situation and artillery just made trench warfare a lot more bloody"), but one could say that 1897 type of artillery is what made WWI so different: artillery's immense range and indirect fire with newly improved accuracy and rate of fire.
The equivalent would be a Dungeons And Dragons style spellcaster with an extended range Fireball at will that they could shoot outside of line of sight.
WWI was the first major usage of really reliable grenades. They were mostly fielded by dedicated assault teams, similar to Light Machine Guns, in an attempt to break the trench warfare. Not really a factor in creating that style of static warfare. It's easy to picture a mage with short range attacks (such as D&D's 'Burning Hands' or 'Circle of Death'). Do remember that grenades are more indirect than traditional short range fantasy magic, though.
Overall in weaponry, you can create trench warfare by making spellcasters dominate the field at long range, forcing everyone to hunker down in trenches. If you want to keep crossbows etc. relevant, then maybe drop some of the range for spellcasters down to 400 or 500 yards or something. Enough to make close combat less viable (thus trenches) but also enough to keep them special compared to mundane weapons. More on close combat further below.
The first mass use of railways for warfare was the 1870 Franco-Prussian War. Prussia prepared a war plan, tricked France into declaring war, then immediately mobilised their massive army and shiny new artillery right into strategic points of France before France had had time to prepare. France had a much better rifle (1866 Chassepot vs the Dreyse), had experimental machineguns (the Millatreuse), but lost spectacularly, mostly because the Prussians caught them by surprise. Which they did by mobilising effectively: getting their troops and their big Krupp artillery into the best spots.
It's not hard to imagine magic portals and gate spells working similarly, although teleporting a whole army (or even one mage) anywhere in the world is not going to work. You're going to have to limit it somehow: e.g. you can teleport X people per day. Or better, you can only teleport from one portal/standing stone/magic circle/ancient ruin, to the next (nearest) portal in the chain/line. Like how a railway train runs linearly.
Air travel can be emulated too. WWI had a small number of scouting planes and (ineffective compared to WWII) bombers. Mages can very easily replicate this, or characters riding giant eagles or similar.
Mining and sapping under strongpoints was also common late in WWI. Easy to create a magic tunnel, or even teleporting a squad at fairly short range.
Size of The Conflict
As the first world war took place across whole borders, nay across the whole of Europe, with millions of troops, whole countries were fortified. It was a frontier. There were few places where a strike force could slip in to a country unnoticed.
Trench warfare did occasionally happen in the middle ages, but only in sieges or while defending a town etc. (see FR Taylor's "The Art Of War In Italy 1494-1529" for some nice examples, even if that's later than the medieval you want to style the world on).
In a medieval war, you have pockets of 1000 and 10,000 men garrisoned in strategic points or wandering the land living off pillage, maybe a total of 100,000 men in your army in total. Armies often bypassed each other, flanking and outmaneuvering were the order of the day. Your 'frontier' was a few castles and towns in an otherwise massive empty stretch of land. There are some exceptions though, e.g. where your southern border is a river. This is where your (smaller population) fantasy world can work.
For your world-building, borders are best placed on a river or ridge or ravine or some other natural feature (e.g. NOT like the USA's mostly artificial borders between perfectly square states). Fantasy worlds are more likely to have epic mountain ranges, grand canyons, raging rivers and other dramatic geographic elements suitable for a frontier. 5000 men guarding a long stretch of open plains is hard, but 5000 guarding a torrentious river with only a few bridges is much easier to picture trenches and static fighting around, interrupted by some specialist assault teams with magic and armour (more on this below).
HOW TRENCH WARFARE AFFECTS THE FANTASY WORLD
And how you can keep your traditional fantasy elements
Knights (Part 1, Armour)
Armour other than basic helmets was only really worn in two years of WWI: 1914 and 1918, the first and the last. Some cavalry were still wearing cuirasses and breastplates during 1914, before the trenches really stuck in. Later in the war, tank crew, machinegun crews, and special assault teams were given breastplate-type armour. No nation could afford armour for everyone (and it was hot and heavy so not that popular), so they assigned it as strategic points: just like how machineguns and tanks were.
Your high level mages (being machineguns and tanks) should be focused in strategic points to attack, and so could your armoured knights. I am picturing the trenches being held mostly by crossbowmen with leather armour and kettle helmets, with a few low-level spellcasters to act as snipers; but attacking strategic points, a few special assault groups of high-level mages and armoured knights.
Knights (Part 2, Cavalry)
Cavalry and Trench Warfare don't mix very well. After 1914, once the trenches were established, cavalry on the western front were mostly kept in reserve, or would be reassigned left and right to different parts of the line as reinforcement. Then they dismounted and fought with rifles. This would work fine for light cavalry, but isn't very knightly. Knights charge in, right?
Now, close combat did happen in the trenches. The first version is a suicidal bayonet charge (or your crossbowmen's daggers, axes and clubs) across no-man's-land. But this didn't happen very often in reality.
The second is a precision strike by specific assault teams. I mentioned earlier how both high-level spellcasters and armoured knights can fill in that assault role. In WWI, the armoured people would be carrying grenades and light machine guns.
In your world, you can separate them into unarmoured mages carrying fireballs, and armoured knights carrying swords and shields. Half a dozen of each would be an assault team which could take on a strongpoint. If you want a medieval strongpoint emulating those of WWI (bunker and MG), then have a dugout with a Wall of Force or Wall of Fire (the bunker) staffed by mages (machinegun).
The army structure and raising methods of WWI is very different from the "feudal system" in fantasy worlds (which didn't really exist in real society - see Melissa Snell's "The F Word: Feudalism" for a summary). However, it's not hard to think of a way they could be combined.
The King demands an army, and assigns a particular area/border/province of the frontier to each lord. Each Lord brings their elite knight-retainers, pays some mercenaries, picks half of each town guard, and levies some peasants. Each Lord also has a court wizard or two who comes along, and can bribe or blackmail one of the local colleges of magic to provide some mages.
So, each lord acts as a lieutenant-general or similar rank. Levied peasants, town guards and mercenaries with crosswbows form the front line of the first trenches, and take massive casualties from enemy mages. Meanwhile, the lord sends the weaker mages to reinforce the trenches ala machine guns and snipe. Some moderately powerful mages are kept as reserves and/or as bombardment artillery.
Then the lord sends his dozen best knights and powerful court wizard with 6 talented apprentices on a specific mission to assault the enemy strongpoint in the mountain pass.